Changeset 1574 for code/branches/core3
- Timestamp:
- Jun 9, 2008, 4:35:38 AM (17 years ago)
- Location:
- code/branches/core3
- Files:
-
- 3 added
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core3/bin/levels/sample.oxw
r1557 r1574 44 44 for i = 1, 226, 1 45 45 do ?> 46 <Model position="<?lua print(math.random() * 40000 - 20000)?>, <?lua print(math.random() * 40000 - 20000) ?>, <?lua print(math.random() * 40000 - 20000) ?>" scale="<?lua print(math.random() * 100 + 20) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" rotationAxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationRate="<?lua print(math.random() * 30 + 15) ?>" />46 <Model position="<?lua print(math.random() * 40000 - 20000)?>, <?lua print(math.random() * 40000 - 20000) ?>, <?lua print(math.random() * 40000 - 20000) ?>" scale="<?lua print(math.random() * 250 + 20) ?>" mesh="ast<?lua print( math.mod(i,6) + 1) ?>.mesh" rotationAxis="<?lua print(math.random()) ?>, <?lua print(math.random()) ?>, <?lua print(math.random()) ?>" rotationRate="<?lua print(math.random() * 30 + 15) ?>" /> 47 47 <?lua 48 48 end -
code/branches/core3/src/core/CMakeLists.txt
r1555 r1574 5 5 Error.cc 6 6 Language.cc 7 ObjectListBase.cc 7 8 OrxonoxClass.cc 8 9 OutputBuffer.cc -
code/branches/core3/src/core/ClassTreeMask.h
r1505 r1574 78 78 namespace orxonox 79 79 { 80 // ############################### 81 // ### ClassTreeMaskNode###82 // ############################### 80 // ################################### 81 // ### ClassTreeMaskNode ### 82 // ################################### 83 83 //! The ClassTreeMaskNode is a node in the internal tree of the ClassTreeMask, containing the rules of the mask. 84 84 /** … … 116 116 117 117 118 // ############################### 119 // ### ClassTreeMaskIterator###120 // ############################### 118 // ################################### 119 // ### ClassTreeMaskIterator ### 120 // ################################### 121 121 //! The ClassTreeMaskIterator moves through all ClassTreeMaskNodes of the internal tree of a ClassTreeMask, containing the rules. 122 122 /** … … 146 146 147 147 148 // ############################### 149 // ### ClassTreeMask###150 // ############################### 148 // ################################### 149 // ### ClassTreeMask ### 150 // ################################### 151 151 //! The ClassTreeMask is a set of rules, containing the information for each class whether it's included or not. 152 152 /** … … 214 214 ClassTreeMaskNode* root_; //!< The root-node of the internal rule-tree, usually BaseObject 215 215 }; 216 217 218 // ################################### 219 // ### ClassTreeMaskObjectIterator ### 220 // ################################### 221 //! ... 222 /** 223 ... 224 */ 225 class _CoreExport ClassTreeMaskObjectIterator 226 { 227 }; 216 228 } 217 229 -
code/branches/core3/src/core/CorePrereqs.h
r1543 r1574 125 125 template <class T> 126 126 class Iterator; 127 class IteratorBase; 127 128 class Language; 128 129 class LanguageEntry; … … 130 131 class Loader; 131 132 class MetaObjectList; 132 template <class T>133 133 class MetaObjectListElement; 134 134 class Namespace; … … 136 136 template <class T> 137 137 class ObjectList; 138 template <class T>139 class ObjectList Element;138 class ObjectListBase; 139 class ObjectListBaseElement; 140 140 class OrxonoxClass; 141 141 class OutputBuffer; -
code/branches/core3/src/core/Identifier.cc
r1543 r1574 39 39 #include "ConsoleCommand.h" 40 40 #include "CommandExecutor.h" 41 #include "MetaObjectList.h" 42 #include "ObjectList.h" 43 #include "OrxonoxClass.h" 41 44 42 45 namespace orxonox … … 52 55 Identifier::Identifier() 53 56 { 57 this->objects_ = new ObjectListBase(this); 58 54 59 this->bCreatedOneObject_ = false; 55 60 this->factory_ = 0; … … 174 179 175 180 /** 181 @brief Adds an object of the given type to the ObjectList. 182 @param object The object to add 183 */ 184 void Identifier::addObject(OrxonoxClass* object) 185 { 186 COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl; 187 object->getMetaList().add(this->objects_, this->objects_->add(object)); 188 } 189 190 /** 176 191 @brief Returns true, if the Identifier is at least of the given type. 177 192 @param identifier The identifier to compare with -
code/branches/core3/src/core/Identifier.h
r1543 r1574 60 60 #include <utility> 61 61 62 #include "ObjectList.h"63 62 #include "Debug.h" 64 63 #include "Iterator.h" 65 #include "MetaObjectList.h"66 64 #include "util/String.h" 67 65 … … 108 106 bool isDirectParentOf(const Identifier* identifier) const; 109 107 110 virtual const ObjectList<BaseObject>* getObjectList() const = 0; 111 112 virtual void updateConfigValues() const = 0; 108 void addObject(OrxonoxClass* object); 109 110 /** @brief Returns the list of all existing objects of this class. @return The list */ 111 inline ObjectListBase* getObjects() const 112 { return this->objects_; } 113 113 114 114 /** @brief Returns the name of the class the Identifier belongs to. @return The name */ 115 115 inline const std::string& getName() const { return this->name_; } 116 116 117 virtual void updateConfigValues() const = 0; 117 118 118 119 /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */ … … 263 264 std::string name_; //!< The name of the class the Identifier belongs to 264 265 266 ObjectListBase* objects_; //!< The list of all objects of this class 265 267 BaseFactory* factory_; //!< The Factory, able to create new objects of the given class (if available) 266 268 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) … … 297 299 public: 298 300 ClassIdentifier<T>* registerClass(std::set<const Identifier*>* parents, const std::string& name, bool bRootClass); 299 void addObject(T* object);300 301 void setName(const std::string& name); 301 /** @brief Returns the list of all existing objects of this class. @return The list */302 inline ObjectList<T>* getObjects() const { return this->objects_; }303 /** @brief Returns a list of all existing objects of this class. @return The list */304 inline ObjectList<BaseObject>* getObjectList() const { return (ObjectList<BaseObject>*)this->objects_; }305 302 306 303 void updateConfigValues() const; … … 319 316 ~ClassIdentifier() {} // don't delete 320 317 321 ObjectList<T>* objects_; //!< The ObjectList, containing all objects of type T322 318 bool bSetName_; //!< True if the name is set 323 319 std::map<std::string, XMLPortClassParamContainer<T>*> xmlportParamContainers_; //!< All loadable parameters … … 336 332 ClassIdentifier<T>::ClassIdentifier() 337 333 { 338 // this->objects_ = ObjectList<T>::getList();339 this->objects_ = new ObjectList<T>();340 334 this->bSetName_ = false; 341 335 } … … 408 402 409 403 /** 410 @brief Adds an object of the given type to the ObjectList.411 @param object The object to add412 */413 template <class T>414 void ClassIdentifier<T>::addObject(T* object)415 {416 COUT(5) << "*** ClassIdentifier: Added object to " << this->getName() << "-list." << std::endl;417 object->getMetaList().add(this->objects_, this->objects_->add(object));418 }419 420 /**421 404 @brief Updates the config-values of all existing objects of this class by calling their setConfigValues() function. 422 405 */ … … 424 407 void ClassIdentifier<T>::updateConfigValues() const 425 408 { 426 for (Iterator<T> it = this->objects_-> start(); it; ++it)427 ( (T*)*it)->setConfigValues();409 for (Iterator<T> it = this->objects_->begin(); it; ++it) 410 (*it)->setConfigValues(); 428 411 } 429 412 -
code/branches/core3/src/core/Iterator.h
r1543 r1574 35 35 36 36 Usage: 37 for (Iterator< class> it = ObjectList<class>::start(); it != 0; ++it)37 for (Iterator<myClass> it = ObjectList<myClass>::begin(); it != ObjectList<myClass>::end(); ++it) 38 38 { 39 39 it->someFunction(...); 40 class* myObject = *it;40 myClass* myObject = *it; 41 41 } 42 43 Warning: Don't delete objects directly through the iterator.44 42 */ 45 43 … … 49 47 #include "CorePrereqs.h" 50 48 51 #include " ObjectList.h"49 #include "IteratorBase.h" 52 50 53 51 namespace orxonox 54 52 { 55 //! The iterator allows to iterate through anObjectList of a given class.53 //! The Iterator allows to iterate through the ObjectList of a given class. 56 54 template <class T> 57 class Iterator 55 class Iterator : public IteratorBase 58 56 { 59 57 public: … … 61 59 @brief Constructor: Sets the element, whereon the iterator points, to zero. 62 60 */ 63 Iterator()61 inline Iterator() 64 62 { 65 this->element_ = 0;66 63 ClassIdentifier<T>::getIdentifier()->getObjects()->registerIterator(this); 67 64 } … … 71 68 @param element The element to start with 72 69 */ 73 Iterator(ObjectListElement<T>*element)70 inline Iterator(ObjectListBaseElement* element) : IteratorBase((ObjectListBaseElement*)element) 74 71 { 75 this->element_ = element;76 72 ClassIdentifier<T>::getIdentifier()->getObjects()->registerIterator(this); 77 73 } … … 80 76 @brief Unregisters the Iterator from the ObjectList. 81 77 */ 82 ~Iterator()78 inline ~Iterator() 83 79 { 84 80 ClassIdentifier<T>::getIdentifier()->getObjects()->unregisterIterator(this); 85 }86 87 /**88 @brief Assigns an element to the iterator.89 @param element The element90 */91 Iterator<T> operator=(ObjectListElement<T>* element)92 {93 this->element_ = element;94 81 } 95 82 … … 98 85 @return The Iterator itself 99 86 */ 100 Iterator<T> operator++()87 inline Iterator<T> operator++() 101 88 { 102 if (this->element_) 103 this->element_ = this->element_->next_; 89 IteratorBase::operator++(); 104 90 return *this; 105 91 } … … 109 95 @return The Iterator itself 110 96 */ 111 Iterator<T> operator++(int i)97 inline Iterator<T> operator++(int i) 112 98 { 113 99 Iterator<T> copy = *this; 114 if (this->element_) 115 this->element_ = this->element_->next_; 100 IteratorBase::operator++(); 116 101 return copy; 117 102 } … … 121 106 @return The Iterator itself 122 107 */ 123 Iterator<T> operator--()108 inline Iterator<T> operator--() 124 109 { 125 if (this->element_) 126 this->element_ = this->element_->prev_; 110 IteratorBase::operator--(); 127 111 return *this; 128 112 } … … 132 116 @return The Iterator itself 133 117 */ 134 Iterator<T> operator--(int i)118 inline Iterator<T> operator--(int i) 135 119 { 136 120 Iterator<T> copy = *this; 137 if (this->element_) 138 this->element_ = this->element_->prev_; 121 IteratorBase::operator--(); 139 122 return copy; 140 123 } … … 144 127 @return The object the Iterator points at 145 128 */ 146 T* operator*()129 inline T* operator*() 147 130 { 148 if (this->element_) 149 return this->element_->object_; 150 else 151 return 0; 131 return dynamic_cast<T*>(IteratorBase::operator*()); 152 132 } 153 133 … … 156 136 @return The object the Iterator points at 157 137 */ 158 T* operator->() const138 inline T* operator->() const 159 139 { 160 if (this->element_) 161 return this->element_->object_; 162 else 163 return 0; 164 140 return dynamic_cast<T*>(IteratorBase::operator->()); 165 141 } 166 142 167 143 /** 168 @brief Overloading of the typecast-operator to bool: returns true if the iterator points to an existing object. 169 @return True if the iterator points to an existing object. 144 @brief Overloading of the == operator to compare with another Iterator. 145 @param compare The other Iterator 146 @return True if the iterators point to the same element 170 147 */ 171 operator bool()148 inline bool operator==(const Iterator<T>& compare) 172 149 { 173 return (this->element_ != 0);150 return (this->element_ == compare.element_); 174 151 } 175 152 176 153 /** 177 @brief Overloading of the (it != int) operator: Used for (it != 0) instead of typecast-operator to bool.178 @param compare The integer (must be zero, everything else makes no sense).179 @return True if the iterator points to an existing object.154 @brief Overloading of the != operator to compare with another Iterator. 155 @param compare The other Iterator 156 @return True if the iterators point to different elements 180 157 */ 181 bool operator!=(ObjectListElement<T>*compare)158 inline bool operator!=(const Iterator<T>& compare) 182 159 { 183 return (this->element_ != compare );160 return (this->element_ != compare.element_); 184 161 } 185 186 private:187 ObjectListElement<T>* element_; //!< The element the Iterator points at188 162 }; 189 163 } 190 164 165 // Include ObjectList.h so the user only has to include one file: Iterator.h 166 #include "ObjectList.h" 167 191 168 #endif /* _Iterator_H__ */ -
code/branches/core3/src/core/Loader.cc
r1505 r1574 32 32 #include "Identifier.h" 33 33 #include "Iterator.h" 34 #include "ObjectList.h" 34 35 #include "Debug.h" 35 36 #include "CoreIncludes.h" … … 91 92 void Loader::unload(const ClassTreeMask& mask) 92 93 { 93 for (Iterator<BaseObject> it = ObjectList<BaseObject>::begin(); it ; )94 for (Iterator<BaseObject> it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ) 94 95 { 95 96 if (mask.isIncluded(it->getIdentifier())) -
code/branches/core3/src/core/MetaObjectList.cc
r1505 r1574 33 33 34 34 #include "MetaObjectList.h" 35 #include "Debug.h" 35 36 36 37 namespace orxonox 37 38 { 39 // ############################### 40 // ### MetaObjectListElement ### 41 // ############################### 42 /** 43 @brief Destructor: Removes the ObjectListBaseElement from the ObjectListBase by linking next_ and prev_ of the ObjectListBaseElement. 44 */ 45 MetaObjectListElement::~MetaObjectListElement() 46 { 47 COUT(5) << "*** MetaObjectList: Removing Object from " << this->list_->getIdentifier()->getName() << "-list." << std::endl; 48 this->list_->notifyIterators(this->element_); 49 50 if (this->element_->next_) 51 this->element_->next_->prev_ = this->element_->prev_; 52 else 53 this->list_->last_ = this->element_->prev_; // If there is no next_, we deleted the last object and have to update the last_ pointer of the list 54 55 if (this->element_->prev_) 56 this->element_->prev_->next_ = this->element_->next_; 57 else 58 this->list_->first_ = this->element_->next_; // If there is no prev_, we deleted the first object and have to update the first_ pointer of the list 59 60 delete this->element_; 61 } 62 63 64 // ############################### 65 // ### MetaObjectList ### 66 // ############################### 38 67 /** 39 68 @brief Constructor: Sets first_ to zero. … … 49 78 MetaObjectList::~MetaObjectList() 50 79 { 51 BaseMetaObjectListElement* temp;80 MetaObjectListElement* temp; 52 81 while (this->first_) 53 82 { … … 57 86 } 58 87 } 88 89 /** 90 @brief Adds an ObjectList and an element of that list to the MetaObjectList. 91 @param list The ObjectList wherein the element is 92 @param element The element wherein the object is 93 */ 94 void MetaObjectList::add(ObjectListBase* list, ObjectListBaseElement* element) 95 { 96 MetaObjectListElement* temp = this->first_; 97 this->first_ = new MetaObjectListElement(list, element); 98 this->first_->next_ = temp; 99 } 59 100 } -
code/branches/core3/src/core/MetaObjectList.h
r1543 r1574 41 41 #include "CorePrereqs.h" 42 42 43 #include "ObjectList .h"43 #include "ObjectListBase.h" 44 44 #include "Identifier.h" 45 #include "Debug.h"46 45 47 46 namespace orxonox 48 47 { 49 //! Base-class of MetaObjectListElement, because those is a template50 class BaseMetaObjectListElement51 {52 public:53 /** @brief Default destructor */54 virtual ~BaseMetaObjectListElement() {};55 56 BaseMetaObjectListElement* next_; //!< The next Element in the list57 };58 59 48 // ############################### 60 49 // ### MetaObjectListElement ### 61 50 // ############################### 62 51 //! The list-element of the MetaObjectList 63 template <class T> 64 class MetaObjectListElement : public BaseMetaObjectListElement 52 class _CoreExport MetaObjectListElement 65 53 { 66 54 public: 67 MetaObjectListElement(ObjectList<T>* list, ObjectListElement<T>* element); 68 virtual ~MetaObjectListElement(); 55 /** 56 @brief Constructor: Creates the list-element with given list and element. 57 */ 58 MetaObjectListElement(ObjectListBase* list, ObjectListBaseElement* element) : next_(0), element_(element), list_(list) {} 59 ~MetaObjectListElement(); 69 60 70 ObjectListElement<T>* element_; //!< The list element, containing the object 71 ObjectList<T>* list_; //!< The list, containing the element 61 MetaObjectListElement* next_; //!< The next Element in the list 62 ObjectListBaseElement* element_; //!< The list element, containing the object 63 ObjectListBase* list_; //!< The list, containing the element 72 64 }; 73 74 /**75 @brief Constructor: Creates the list-element with given list and element.76 */77 template <class T>78 MetaObjectListElement<T>::MetaObjectListElement(ObjectList<T>* list, ObjectListElement<T>* element)79 {80 this->element_ = element;81 this->list_ = list;82 this->next_ = 0;83 }84 85 /**86 @brief Destructor: Removes the ObjectListElement from the ObjectList by linking next_ and prev_ of the ObjectListElement.87 */88 template <class T>89 MetaObjectListElement<T>::~MetaObjectListElement()90 {91 COUT(5) << "*** MetaObjectList: Removing Object from " << ClassIdentifier<T>::getIdentifier()->getName() << "-list." << std::endl;92 this->list_->notifyIterators(this->element_);93 94 if (this->element_->next_)95 this->element_->next_->prev_ = this->element_->prev_;96 else97 this->list_->last_ = this->element_->prev_; // If there is no next_, we deleted the last object and have to update the last_ pointer of the list98 99 if (this->element_->prev_)100 this->element_->prev_->next_ = this->element_->next_;101 else102 this->list_->first_ = this->element_->next_; // If there is no prev_, we deleted the first object and have to update the first_ pointer of the list103 104 delete this->element_;105 }106 65 107 66 … … 109 68 // ### MetaObjectList ### 110 69 // ############################### 111 //! The MetaObjectList contains ObjectList Elements and their ObjectLists.70 //! The MetaObjectList contains ObjectListBaseElements and their ObjectListBases. 112 71 /** 113 72 The MetaObjectList is a single-linked list, containing all list-elements and their … … 120 79 MetaObjectList(); 121 80 ~MetaObjectList(); 122 template <class T> 123 void add(ObjectList<T>* list, ObjectListElement<T>* element); 81 void add(ObjectListBase* list, ObjectListBaseElement* element); 124 82 125 BaseMetaObjectListElement* first_; //!< The first element in the list83 MetaObjectListElement* first_; //!< The first element in the list 126 84 }; 127 128 /**129 @brief Adds an ObjectList and an element of that list to the MetaObjectList.130 @param list The ObjectList wherein the element is131 @param element The element wherein the object is132 */133 template <class T>134 void MetaObjectList::add(ObjectList<T>* list, ObjectListElement<T>* element)135 {136 BaseMetaObjectListElement* temp = this->first_;137 this->first_ = new MetaObjectListElement<T>(list, element);138 this->first_->next_ = temp;139 }140 85 } 141 86 -
code/branches/core3/src/core/ObjectList.h
r1543 r1574 31 31 @brief Definition and implementation of the ObjectList class. 32 32 33 The ObjectList is a double-linked list, used by Identifiers to store all objects of a given class. 34 Newly created objects are added through the RegisterObject-macro in its constructor. 33 The ObjectList is a wrapper of an ObjectListBase of a given class. 35 34 Use Iterator<class> to iterate through all objects of the class. 36 35 */ … … 39 38 #define _ObjectList_H__ 40 39 41 #include <set>42 43 40 #include "CorePrereqs.h" 44 41 42 #include "Identifier.h" 45 43 #include "Iterator.h" 46 #include "Identifier.h"47 44 48 45 namespace orxonox 49 46 { 50 47 // ############################### 51 // ### ObjectListElement ###52 // ###############################53 //! The list-element of the ObjectList54 template <class T>55 class ObjectListElement56 {57 public:58 ObjectListElement(T* object);59 60 T* object_; //!< The object61 ObjectListElement* next_; //!< The next element in the list62 ObjectListElement* prev_; //!< The previous element in the list63 };64 65 /**66 @brief Constructor: Creates the list-element with an object.67 @param object The object to store68 */69 template <class T>70 ObjectListElement<T>::ObjectListElement(T* object)71 {72 this->object_ = object;73 this->next_ = 0;74 this->prev_ = 0;75 }76 77 78 // ###############################79 48 // ### ObjectList ### 80 49 // ############################### 81 //! The ObjectList contains all objects of agiven class.50 //! The ObjectList contains all objects of the given class. 82 51 /** 83 The ObjectList is used by Identifiers to store all objects of a given class.52 Wraps the ObjectListBase of the corresponding Identifier. 84 53 Use Iterator<class> to iterate through all objects in the list. 85 54 */ … … 88 57 { 89 58 public: 90 ObjectList(); 91 ~ObjectList(); 59 /** @brief Returns an Iterator to the first element in the list. @return The Iterator */ 60 inline static Iterator<T> begin() 61 { return Iterator<T>(ClassIdentifier<T>::getIdentifier()->getObjects()->begin()); } 92 62 93 ObjectListElement<T>* add(T* object); 63 /** @brief Returns an Iterator to the element after the last element in the list. @return The Iterator */ 64 inline static Iterator<T> end() 65 { return Iterator<T>(ClassIdentifier<T>::getIdentifier()->getObjects()->end()); } 94 66 95 /** @brief Returns the first element in the list. @return The first element*/96 inline static Iterator<T> start()97 { return Iterator<T>(ClassIdentifier<T>::getIdentifier()->getObjects()-> first_); }67 /** @brief Returns an Iterator to the last element in the list. @return The Iterator */ 68 inline static Iterator<T> rbegin() 69 { return Iterator<T>(ClassIdentifier<T>::getIdentifier()->getObjects()->rbegin()); } 98 70 99 /** @brief Returns the first element in the list. @return The first element */ 100 inline static Iterator<T> begin() 101 { return Iterator<T>(ClassIdentifier<T>::getIdentifier()->getObjects()->first_); } 102 103 /** @brief Returns the last element in the list. @return The last element */ 104 inline static Iterator<T> end() 105 { return Iterator<T>(ClassIdentifier<T>::getIdentifier()->getObjects()->last_); } 106 107 inline void registerIterator(Iterator<T>* iterator) 108 { this->iterators_.insert(this->iterators_.end(), (void*)iterator); } 109 inline void unregisterIterator(Iterator<T>* iterator) 110 { this->iterators_.erase((void*)iterator); } 111 void notifyIterators(ObjectListElement<T>* element); 112 113 ObjectListElement<T>* first_; //!< The first element in the list 114 ObjectListElement<T>* last_; //!< The last element in the list 115 116 private: 117 std::set<void*> iterators_; //!< A list of iterators pointing on an element in this list 71 /** @brief Returns an Iterator to the element before the first element in the list. @return The Iterator */ 72 inline static Iterator<T> rend() 73 { return Iterator<T>(ClassIdentifier<T>::getIdentifier()->getObjects()->rend()); } 118 74 }; 119 120 /**121 @brief Constructor: Sets default values.122 */123 template <class T>124 ObjectList<T>::ObjectList()125 {126 this->first_ = 0;127 this->last_ = 0;128 }129 130 /**131 @brief Destructor: Deletes all list-elements, but NOT THE OBJECTS.132 */133 template <class T>134 ObjectList<T>::~ObjectList()135 {136 ObjectListElement<T>* temp;137 while (this->first_)138 {139 temp = this->first_->next_;140 delete this->first_;141 this->first_ = temp;142 }143 }144 145 /**146 @brief Increases all Iterators that currently point on the given element (because it gets removed).147 @param element The element that gets removed148 */149 template <class T>150 void ObjectList<T>::notifyIterators(ObjectListElement<T>* element)151 {152 for (std::set<void*>::iterator it = this->iterators_.begin(); it != this->iterators_.end(); ++it)153 if ((*(*((Iterator<T>*)(*it)))) == element->object_)154 ++(*((Iterator<T>*)(*it)));155 }156 157 /**158 @brief Adds a new object to the end of the list.159 @param object The object to add160 @return The pointer to the new ObjectListElement, needed by the MetaObjectList of the added object161 */162 template <class T>163 ObjectListElement<T>* ObjectList<T>::add(T* object)164 {165 if (!this->last_)166 {167 // If the list is empty168 this->last_ = new ObjectListElement<T>(object);169 this->first_ = this->last_; // There's only one object in the list now170 }171 else172 {173 // If the list isn't empty174 ObjectListElement<T>* temp = this->last_;175 this->last_ = new ObjectListElement<T>(object);176 this->last_->prev_ = temp;177 temp->next_ = this->last_;178 }179 180 return this->last_;181 }182 75 } 183 76 -
code/branches/core3/src/core/OrxonoxClass.cc
r1505 r1574 39 39 { 40 40 /** @brief Constructor: Sets the default values. */ 41 OrxonoxClass::OrxonoxClass() : 42 identifier_(0), 43 parents_(0) 41 OrxonoxClass::OrxonoxClass() 44 42 { 43 this->identifier_ = 0; 44 this->parents_ = 0; 45 45 this->metaList_ = new MetaObjectList(); 46 46 -
code/branches/core3/src/network/ConnectionManager.cc
r1534 r1574 64 64 { 65 65 //boost::thread_group network_threads; 66 66 67 67 ConnectionManager::ConnectionManager():receiverThread_(0){} 68 68 boost::recursive_mutex ConnectionManager::enet_mutex_; 69 69 70 70 ConnectionManager::ConnectionManager(ClientInformation *head) : receiverThread_(0) { 71 71 quit=false; … … 74 74 head_ = head; 75 75 } 76 76 77 77 ConnectionManager::ConnectionManager(ClientInformation *head, int port){ 78 78 quit=false; … … 115 115 return packet; 116 116 }*/ 117 117 118 118 ENetEvent *ConnectionManager::getEvent(){ 119 119 if(!buffer.isEmpty()) … … 251 251 } 252 252 } 253 253 254 254 //### added some bugfixes here, but we cannot test them because 255 255 //### the server crashes everytime because of some gamestates … … 333 333 } 334 334 335 336 335 336 337 337 bool ConnectionManager::removeShip(ClientInformation *client){ 338 338 int id=client->getShipID(); 339 339 orxonox::Iterator<orxonox::SpaceShip> it; 340 for(it = orxonox::ObjectList<orxonox::SpaceShip>:: start(); it; ++it){340 for(it = orxonox::ObjectList<orxonox::SpaceShip>::begin(); it; ++it){ 341 341 if(it->objectID!=id) 342 342 continue; … … 345 345 return true; 346 346 } 347 347 348 348 bool ConnectionManager::sendWelcome(int clientID, int shipID, bool allowed){ 349 349 if(addPacket(packet_gen.generateWelcome(clientID, shipID, allowed),clientID)){ … … 353 353 return false; 354 354 } 355 355 356 356 void ConnectionManager::disconnectClient(ClientInformation *client){ 357 357 { … … 362 362 removeShip(client); 363 363 } 364 364 365 365 bool ConnectionManager::addFakeConnectRequest(ENetEvent *ev){ 366 366 ENetEvent event; … … 369 369 return buffer.push(&event); 370 370 } 371 372 371 372 373 373 374 374 } -
code/branches/core3/src/network/GameStateClient.cc
r1534 r1574 151 151 COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl; 152 152 // get the start of the Synchronisable list 153 orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>:: start();153 orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::begin(); 154 154 syncData sync; 155 155 // loop as long as we have some data ;) … … 236 236 int offset=0, size=0; 237 237 // get total size of gamestate 238 for(it = orxonox::ObjectList<Synchronisable>:: start(); it; ++it){238 for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){ 239 239 if(!it->getBacksync()) 240 240 continue; … … 253 253 memsize=size; 254 254 // go through all Synchronisables 255 for(it = orxonox::ObjectList<Synchronisable>:: start(); it; ++it){255 for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){ 256 256 if(!it->getBacksync()) 257 257 continue; -
code/branches/core3/src/network/GameStateManager.cc
r1534 r1574 70 70 return; 71 71 } 72 72 73 73 void GameStateManager::addGameState(GameStateCompressed *gs, int clientID){ 74 74 if(!gs) … … 83 83 return; 84 84 } 85 85 86 86 void GameStateManager::processGameStates(){ 87 87 std::map<int, GameStateCompressed*>::iterator it; … … 93 93 gameStateQueue.clear(); 94 94 } 95 96 95 96 97 97 /** 98 98 * this function is used to keep the memory usage low 99 99 * it tries to delete all the unused gamestates 100 * 101 * 100 * 101 * 102 102 */ 103 103 void GameStateManager::cleanup(){ … … 155 155 } 156 156 } 157 157 158 158 bool GameStateManager::pushGameState( GameStateCompressed *gs, int clientID ){ 159 159 GameState *ugs = decompress(gs); … … 190 190 int offset=0, size=0; 191 191 // get total size of gamestate 192 for(it = orxonox::ObjectList<Synchronisable>:: start(); it; ++it){192 for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){ 193 193 size+=it->getSize(); // size of the actual data of the synchronisable 194 194 size+=3*sizeof(int); // size of datasize, classID and objectID … … 204 204 memsize=size; 205 205 // go through all Synchronisables 206 for(it = orxonox::ObjectList<Synchronisable>:: start(); it; ++it){206 for(it = orxonox::ObjectList<Synchronisable>::begin(); it; ++it){ 207 207 //get size of the synchronisable 208 208 tempsize=it->getSize(); … … 246 246 COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl; 247 247 // get the start of the Synchronisable list 248 orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>:: start();248 orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::begin(); 249 249 syncData sync; 250 250 /*ClientInformation *client = head_->findClient(clientID); … … 308 308 return true; 309 309 } 310 311 310 311 312 312 //##### ADDED FOR TESTING PURPOSE ##### 313 313 GameStateCompressed* GameStateManager::testCompress( GameState* g ) { … … 405 405 switch ( retval ) { 406 406 case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break; 407 case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; 407 case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; 408 408 return NULL; 409 409 case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl; … … 426 426 return compressedGamestate; 427 427 } 428 428 429 429 GameState *GameStateManager::decompress(GameStateCompressed *a) { 430 430 //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl; … … 464 464 return gamestate; 465 465 } 466 466 467 467 468 468 void GameStateManager::ackGameState(int clientID, int gamestateID) { … … 471 471 return; 472 472 int curid = temp->getGamestateID(); 473 473 474 474 if(gamestateID == GAMESTATEID_INITIAL){ 475 475 temp->setGameStateID(GAMESTATEID_INITIAL); … … 481 481 } 482 482 if(curid > gamestateID) 483 // the network packets got messed up 483 // the network packets got messed up 484 484 return; 485 485 COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl; … … 512 512 return true; 513 513 } 514 514 515 515 bool GameStateManager::checkAccess(int clientID, int objectID){ 516 516 // currently we only check, wheter the object is the clients spaceship … … 518 518 return true; // TODO: change this 519 519 } 520 520 521 521 void GameStateManager::removeClient(ClientInformation* client){ 522 522 if(!client) -
code/branches/core3/src/network/Server.cc
r1556 r1574 57 57 #define MAX_FAILURES 20; 58 58 #define NETWORK_FREQUENCY 30 59 59 60 60 Server *Server::instance_=0; 61 61 62 62 Server *Server::createSingleton(){ 63 63 if(!instance_) … … 80 80 return instance_; 81 81 } 82 82 83 83 Server *Server::getSingleton(){ 84 84 return instance_; 85 85 } 86 87 86 87 88 88 /** 89 89 * Constructor for default values (bindaddress is set to ENET_HOST_ANY … … 97 97 gamestates = new GameStateManager(clients); 98 98 } 99 99 100 100 Server::Server(int port){ 101 101 timeSinceLastUpdate_=0; … … 217 217 if(clients->findClient(&event->peer->address)){ 218 218 clientID = clients->findClient(&event->peer->address)->getID(); 219 if( !elaborate(event->packet, clientID) ) 219 if( !elaborate(event->packet, clientID) ) 220 220 COUT(3) << "Server: could not elaborate" << std::endl; 221 221 } … … 276 276 continue; 277 277 if ( !(connection->addPacket(packet, cid)) ){ 278 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 278 COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl; 279 279 temp->addFailure(); 280 280 /*if(temp->getFailures() > 0 ) … … 302 302 delete data; 303 303 } 304 304 305 305 bool Server::processConnectRequest( connectRequest *con, int clientID ){ 306 306 //(COUT(3) << "processing connectRequest " << std::endl; … … 310 310 return true; 311 311 } 312 312 313 313 void Server::processGamestate( GameStateCompressed *data, int clientID){ 314 314 COUT(4) << "processing partial gamestate from client " << clientID << std::endl; … … 319 319 clients->findClient(clientID)->resetFailures();*/ 320 320 } 321 321 322 322 void Server::processChat( chat *data, int clientId){ 323 323 char *message = new char [strlen(data->message)+10+1]; … … 329 329 delete data; 330 330 } 331 331 332 332 bool Server::addClient(ENetEvent *event){ 333 333 ClientInformation *temp = clients->insertBack(new ClientInformation); … … 346 346 return createClient(temp->getID()); 347 347 } 348 348 349 349 bool Server::createClient(int clientID){ 350 350 ClientInformation *temp = clients->findClient(clientID); … … 366 366 return true; 367 367 } 368 368 369 369 bool Server::createShip(ClientInformation *client){ 370 370 if(!client) … … 390 390 no->classID = id->getNetworkID(); 391 391 no->create(); 392 392 393 393 client->setShipID(no->objectID); 394 394 return true; 395 395 } 396 396 397 397 bool Server::disconnectClient(ENetEvent *event){ 398 398 COUT(4) << "removing client from list" << std::endl; 399 399 //return removeClient(head_->findClient(&(peer->address))->getID()); 400 400 401 401 //boost::recursive_mutex::scoped_lock lock(head_->mutex_); 402 orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>:: start();402 orxonox::Iterator<orxonox::SpaceShip> it = orxonox::ObjectList<orxonox::SpaceShip>::begin(); 403 403 ClientInformation *client = clients->findClient(&event->peer->address); 404 404 if(!client) … … 426 426 gamestates->removeClient(client); 427 427 } 428 428 429 429 } -
code/branches/core3/src/orxonox/Orxonox.cc
r1567 r1574 462 462 Core::tick((float)evt.timeSinceLastFrame); 463 463 // Call those objects that need the real time 464 for (Iterator<TickableReal> it = ObjectList<TickableReal>:: start(); it; ++it)464 for (Iterator<TickableReal> it = ObjectList<TickableReal>::begin(); it; ++it) 465 465 it->tick((float)evt.timeSinceLastFrame); 466 466 // Call the scene objects 467 for (Iterator<Tickable> it = ObjectList<Tickable>:: start(); it; ++it)467 for (Iterator<Tickable> it = ObjectList<Tickable>::begin(); it; ++it) 468 468 it->tick((float)evt.timeSinceLastFrame * this->timefactor_); 469 469 //AudioManager::tick(); -
code/branches/core3/src/orxonox/objects/NPC.cc
r1505 r1574 61 61 movable_ = movable; 62 62 } 63 63 64 64 void NPC::registerAllVariables(){ 65 65 Model::registerAllVariables(); 66 66 registerVar(&movable_, sizeof(movable_), network::DATA); 67 67 } 68 68 69 69 70 70 /** … … 117 117 int numberOfNeighbour = 0; //number of observed neighbours 118 118 float distance = 0; // distance to the actual element 119 for(Iterator<WorldEntity> it = ObjectList<WorldEntity>:: start(); it; ++it) { //go through all elements119 for(Iterator<WorldEntity> it = ObjectList<WorldEntity>::begin(); it; ++it) { //go through all elements 120 120 distance = getDistance(*it); //get distance between this and actual 121 121 if ((distance > 0) && (distance < SEPERATIONDISTANCE)) { //do only if actual is inside detectionradius … … 144 144 //float distance = 0; 145 145 //go through all elements 146 for(Iterator<NPC> it = ObjectList<NPC>:: start(); it; ++it) { //just working with 3 elements at the moment146 for(Iterator<NPC> it = ObjectList<NPC>::begin(); it; ++it) { //just working with 3 elements at the moment 147 147 float distance = getDistance(*it); //get distance between this and actual 148 148 if ((distance > 0) && (distance < ALIGNMENTDISTANCE)) { //check if actual element is inside detectionradius … … 164 164 //float distance = 0; 165 165 //go through all elements 166 for(Iterator<NPC> it = ObjectList<NPC>:: start(); it; ++it) { //just working with 3 elements at the moment166 for(Iterator<NPC> it = ObjectList<NPC>::begin(); it; ++it) { //just working with 3 elements at the moment 167 167 float distance = getDistance(*it); //get distance between this and actual 168 168 if ((distance > 0) && (distance < COHESIONDISTANCE)) { //check if actual element is inside detectionradius -
code/branches/core3/src/orxonox/objects/Projectile.cc
r1563 r1574 86 86 87 87 float radius; 88 for (Iterator<Model> it = ObjectList<Model>:: start(); it; ++it)88 for (Iterator<Model> it = ObjectList<Model>::begin(); it; ++it) 89 89 { 90 90 if ((*it) != this->owner_) -
code/branches/core3/src/orxonox/objects/SpaceShip.cc
r1564 r1574 72 72 SpaceShip *SpaceShip::getLocalShip(){ 73 73 Iterator<SpaceShip> it; 74 for(it = ObjectList<SpaceShip>:: start(); it; ++it){74 for(it = ObjectList<SpaceShip>::begin(); it; ++it){ 75 75 if( (it)->myShip_ ) 76 76 return *it;
Note: See TracChangeset
for help on using the changeset viewer.