- Timestamp:
- Mar 5, 2008, 11:07:16 PM (17 years ago)
- Location:
- code/branches/core
- Files:
-
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core/bin/levels/sample.oxw
r853 r856 36 36 37 37 <Model name="starship" position="(200,0,500)" scale="10" mesh="starship.mesh" yaw="-90" pitch="-90" /> 38 <Model name="drone" position="-200,0,500" scale="10" mesh="drone.mesh" yaw="-90" pitch="-90" /> 38 <Model name="drone" position="-200,0,500" scale="10" mesh="drone.mesh" yaw="-90" pitch="-90"> 39 <attached> 40 <Model name="drone2" position="200,-100,-500" scale="10" mesh="drone.mesh" yaw="-90" pitch="-90"> 41 <attached> 42 <Model name="starship2" position="(500,200,-500)" scale="10" mesh="starship.mesh" yaw="-90" pitch="-90" /> 43 </attached> 44 </Model> 45 </attached> 46 </Model> 39 47 <!-- 40 48 <Model position="-200,1000,500" scale="10" mesh="hoover_body.mesh" yaw="-90" pitch="-90" /> … … 51 59 <!-- Unused at the moment --> 52 60 <!-- <SpaceshipSteeringObject node="OgreHeadNode" forward="500" rotateupdown="200" rotaterightleft="200" looprightleft="200" /> --> 53 61 <!-- 54 62 <script file="intro.lua" /> 63 --> -
code/branches/core/src/orxonox/core/BaseObject.cc
r853 r856 36 36 #include "BaseObject.h" 37 37 #include "XMLPort.h" 38 #include "Level.h" 38 39 39 40 namespace orxonox … … 79 80 Element& BaseObject::XMLPort(Element& xmlelement, bool loading) 80 81 { 81 std::cout << "1_1: " << this->getName() << std::endl;82 82 XMLPortParam(BaseObject, "name", setName, getName, xmlelement, loading); 83 std::cout << "1_2: " << this->getName() << std::endl; 83 84 84 return xmlelement; 85 85 } 86 87 /** 88 @brief Returns the levelfile that loaded this object. 89 @return The levelfile 90 */ 91 const std::string& BaseObject::getLevelfile() const 92 { 93 return this->level_->getFile(); 94 } 86 95 } -
code/branches/core/src/orxonox/core/BaseObject.h
r852 r856 77 77 /** @brief Returns a pointer to the level that loaded this object. @return The level */ 78 78 inline const Level* getLevel() const { return this->level_; } 79 const std::string& getLevelfile() const; 80 81 /** @brief Sets the indentation of the debug output in the Loader. @param indentation The indentation */ 82 inline void setLoaderIndentation(const std::string& indentation) { this->loaderIndentation_ = indentation; } 83 /** @brief Returns the indentation of the debug output in the Loader. @return The indentation */ 84 inline const std::string& getLoaderIndentation() const { return this->loaderIndentation_; } 79 85 80 86 private: … … 83 89 bool bVisible_; //!< True = the object is visible 84 90 const Level* level_; //!< The level that loaded this object 91 std::string loaderIndentation_; //!< Indentation of the debug output in the Loader 85 92 }; 86 93 } -
code/branches/core/src/orxonox/core/CorePrereqs.h
r847 r856 103 103 template <class T> 104 104 class SubclassIdentifier; 105 class XMLPortParamContainer; 105 template <class T, class O> 106 class XMLPortClassObjectContainer; 106 107 template <class T> 107 108 class XMLPortClassParamContainer; 109 class XMLPortObjectContainer; 110 class XMLPortParamContainer; 108 111 } 109 112 -
code/branches/core/src/orxonox/core/Debug.h
r813 r856 55 55 #define ORX_PRINT_DEBUG_OUTPUT 1 // <-- fix that! should be a configurable setting 56 56 57 #define ORX_HARD_DEBUG_LEVEL ORX_ DEBUG57 #define ORX_HARD_DEBUG_LEVEL ORX_vDEBUG 58 58 //#define ORX_SOFT_DEBUG_LEVEL ORX_WARNING // <-- fix that! should be a configurable setting 59 59 -
code/branches/core/src/orxonox/core/Identifier.h
r847 r856 62 62 #include "Debug.h" 63 63 #include "Iterator.h" 64 //#include "XMLPort.h"65 64 66 65 namespace orxonox … … 158 157 virtual void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) = 0; 159 158 159 virtual XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname) = 0; 160 virtual void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) = 0; 161 160 162 static bool identifierIsInList(const Identifier* identifier, const std::list<const Identifier*>& list); 161 163 … … 238 240 void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container); 239 241 242 XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname); 243 void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container); 244 240 245 private: 241 246 ClassIdentifier(); … … 246 251 bool bSetName_; //!< True if the name is set 247 252 std::map<std::string, XMLPortClassParamContainer<T>*> xmlportParamContainers_; 253 std::map<std::string, XMLPortClassObjectContainer<T, class O>*> xmlportObjectContainers_; 248 254 }; 249 255 … … 336 342 { 337 343 this->xmlportParamContainers_[paramname] = (XMLPortClassParamContainer<T>*)container; 344 } 345 346 template <class T> 347 XMLPortObjectContainer* ClassIdentifier<T>::getXMLPortObjectContainer(const std::string& sectionname) 348 { 349 typename std::map<std::string, XMLPortClassObjectContainer<T, class O>*>::const_iterator it = xmlportObjectContainers_.find(sectionname); 350 if (it != xmlportObjectContainers_.end()) 351 return (XMLPortObjectContainer*)((*it).second); 352 else 353 return 0; 354 } 355 356 template <class T> 357 void ClassIdentifier<T>::addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) 358 { 359 this->xmlportObjectContainers_[sectionname] = (XMLPortClassObjectContainer<T, class O>*)container; 338 360 } 339 361 -
code/branches/core/src/orxonox/core/Level.h
r843 r856 32 32 33 33 #include "CorePrereqs.h" 34 #include "ClassTreeMask.h" 34 35 35 36 namespace orxonox -
code/branches/core/src/orxonox/core/Loader.cc
r852 r856 39 39 { 40 40 std::vector<std::pair<const Level*, ClassTreeMask> > Loader::levels_s; 41 ClassTreeMask Loader::currentMask_s; 41 42 42 43 bool Loader::open(const Level* level, const ClassTreeMask& mask) … … 104 105 bool Loader::load(const Level* level, const ClassTreeMask& mask) 105 106 { 106 ClassTreeMask loadmask= level->getMask() * mask;107 Loader::currentMask_s = level->getMask() * mask; 107 108 108 109 try 109 110 { 110 111 COUT(0) << "Start loading " << level->getFile() << "..." << std::endl; 111 COUT(3) << "Mask: " << loadmask<< std::endl;112 COUT(3) << "Mask: " << Loader::currentMask_s << std::endl; 112 113 113 114 ticpp::Document xmlfile(level->getFile()); 114 115 xmlfile.LoadFile(); 115 116 116 for ( ticpp::Iterator< ticpp::Element > child = xmlfile.FirstChildElement(); child != child.end(); child++ )117 for ( ticpp::Iterator<ticpp::Element> child = xmlfile.FirstChildElement(false); child != child.end(); child++ ) 117 118 { 118 119 Identifier* identifier = ID(child->Value()); 119 120 if (identifier) 120 121 { 121 COUT(4) << " fabricating " << child->Value() << "..." << std::endl; 122 BaseObject* newObject = identifier->fabricate(); 123 newObject->XMLPort(*child, true); 122 if (Loader::currentMask_s.isIncluded(identifier)) 123 { 124 COUT(4) << " fabricating " << child->Value() << "..." << std::endl; 125 BaseObject* newObject = identifier->fabricate(); 126 newObject->setLoaderIndentation(" "); 127 newObject->setLevel(level); 128 newObject->XMLPort(*child, true); 129 COUT(5) << " ...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl; 130 } 124 131 } 125 132 else 126 133 { 127 COUT(2) << " Warning: '" << child->Value() <<"' is not a valid classname." << std::endl;134 COUT(2) << " Warning: '" << child->Value() << "' is not a valid classname." << std::endl; 128 135 } 129 136 } … … 135 142 catch(ticpp::Exception& ex) 136 143 { 144 COUT(1) << std::endl; 137 145 COUT(1) << "An error occurred in Loader.cc while loading " << level->getFile() << ":" << std::endl; 138 146 COUT(1) << ex.what() << std::endl; -
code/branches/core/src/orxonox/core/Loader.h
r826 r856 56 56 static bool reload(const Level* level, const ClassTreeMask& mask = ClassTreeMask()); 57 57 58 static ClassTreeMask currentMask_s; 59 58 60 private: 59 61 static std::vector<std::pair<const Level*, ClassTreeMask> > levels_s; -
code/branches/core/src/orxonox/core/XMLPort.cc
r847 r856 31 31 namespace orxonox 32 32 { 33 // ############################### 34 // ### XMLPortParamContainer ### 35 // ############################### 33 36 XMLPortParamContainer::XMLPortParamContainer() 34 37 { … … 53 56 return GetLocalisation(this->description_); 54 57 } 58 59 60 // ################################ 61 // ### XMLPortObjectContainer ### 62 // ################################ 63 XMLPortObjectContainer::XMLPortObjectContainer() 64 { 65 this->bAddedDescription_ = false; 66 } 67 68 XMLPortObjectContainer& XMLPortObjectContainer::description(const std::string description) 69 { 70 if (!this->bAddedDescription_) 71 { 72 this->description_ = std::string("XMLPortObjectContainer::" + this->classname_ + "::" + this->sectionname_); 73 AddLanguageEntry(this->description_, description); 74 this->bAddedDescription_ = true; 75 } 76 77 return (*this); 78 } 79 80 const std::string& XMLPortObjectContainer::getDescription() 81 { 82 return GetLocalisation(this->description_); 83 } 55 84 } -
code/branches/core/src/orxonox/core/XMLPort.h
r854 r856 35 35 #include "Functor.h" 36 36 #include "Debug.h" 37 #include "CoreIncludes.h" 38 #include "BaseObject.h" 39 #include "Loader.h" 37 40 38 41 #include "CorePrereqs.h" … … 57 60 xmlcontainer##loadfunction##savefunction->port(this, xmlelement, loading) 58 61 62 #define XMLPortObject(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, loading) \ 63 orxonox::XMLPortClassObjectContainer<classname, objectclass>* xmlcontainer##loadfunction##savefunction = (orxonox::XMLPortClassObjectContainer<classname, objectclass>*)(this->getIdentifier()->getXMLPortObjectContainer(sectionname)); \ 64 if (!xmlcontainer##loadfunction##savefunction) \ 65 { \ 66 xmlcontainer##loadfunction##savefunction = new orxonox::XMLPortClassObjectContainer<classname, objectclass>(this->getIdentifier()->getName(), std::string(sectionname), &classname::loadfunction, &classname::savefunction); \ 67 this->getIdentifier()->addXMLPortObjectContainer(sectionname, xmlcontainer##loadfunction##savefunction); \ 68 } \ 69 xmlcontainer##loadfunction##savefunction->port(this, xmlelement, loading) 70 71 59 72 namespace orxonox 60 73 { 74 // ############################### 75 // ### XMLPortParamContainer ### 76 // ############################### 61 77 class _CoreExport XMLPortParamContainer 62 78 { … … 108 124 if (loading) 109 125 { 110 std::string attribute = xmlelement.GetAttribute(this->paramname_); 111 if (attribute.size() > 0) 112 { 113 SubString tokens(attribute, ",", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 114 if ((unsigned int)tokens.size() >= (unsigned int)this->loadfunction_->getParamCount()) 126 try 127 { 128 std::string attribute = xmlelement.GetAttribute(this->paramname_); 129 if (attribute.size() > 0) 115 130 { 116 if (this->loadfunction_->getParamCount() == 1) 131 SubString tokens(attribute, ",", SubString::WhiteSpaces, false, '\\', '"', '(', ')', '\0'); 132 if ((unsigned int)tokens.size() >= (unsigned int)this->loadfunction_->getParamCount()) 117 133 { 118 (*this->loadfunction_)(object, MultiTypeMath(attribute)); 134 COUT(5) << object->getLoaderIndentation() << "Loading parameter " << this->paramname_ << " in " << this->classname_ << " (objectname " << object->getName() << ") with "; 135 if (this->loadfunction_->getParamCount() == 1) 136 { 137 COUT(5) << "1 parameter (using whole string):" << std::endl; 138 COUT(5) << object->getLoaderIndentation() << " " << attribute << std::endl; 139 (*this->loadfunction_)(object, MultiTypeMath(attribute)); 140 } 141 else 142 { 143 COUT(5) << tokens.size() << " parameter (using MultiTypeMath)." << std::endl; 144 MultiTypeMath param1, param2, param3, param4, param5; 145 if (tokens.size() >= 1) param1 = tokens[0]; 146 if (tokens.size() >= 2) param1 = tokens[1]; 147 if (tokens.size() >= 3) param1 = tokens[2]; 148 if (tokens.size() >= 4) param1 = tokens[3]; 149 if (tokens.size() >= 5) param1 = tokens[4]; 150 COUT(5) << object->getLoaderIndentation() << " " << attribute << std::endl; 151 COUT(5) << object->getLoaderIndentation() << " " << tokens[0] << " -> " << param1 << ", " << tokens[1] << " -> " << param2 << ", " << tokens[2] << " -> " << param3 << ", " << tokens[3] << " -> " << param4 << ", " << tokens[4] << " -> " << param5 << std::endl; 152 153 (*this->loadfunction_)(object, param1, param2, param3, param4, param5); 154 } 119 155 } 120 156 else 121 157 { 122 MultiTypeMath param1, param2, param3, param4, param5; 123 if (tokens.size() >= 1) param1 = tokens[0]; 124 if (tokens.size() >= 2) param1 = tokens[1]; 125 if (tokens.size() >= 3) param1 = tokens[2]; 126 if (tokens.size() >= 4) param1 = tokens[3]; 127 if (tokens.size() >= 5) param1 = tokens[4]; 128 129 (*this->loadfunction_)(object, param1, param2, param3, param4, param5); 158 COUT(2) << object->getLoaderIndentation() << "Warning: Parameter \"" << this->paramname_ << "\" in \"" << this->classname_ << "\" (objectname: " << object->getName() << ") is incomplete and couln't be loaded." << std::endl; 130 159 } 131 160 } 132 else 133 { 134 COUT(2) << " Warning: Parameter \"" << this->paramname_ << "\" in \"" << this->classname_ << "\" (objectname: " << object->getName() << ") is incomplete and couln't be loaded." << std::endl; 135 } 161 } 162 catch(ticpp::Exception& ex) 163 { 164 COUT(1) << std::endl; 165 COUT(1) << "An error occurred in XMLPort.h while loading attribute '" << this->paramname_ << "' of '" << this->classname_ << "' (objectname: " << object->getName() << ") in " << object->getLevelfile() << ":" << std::endl; 166 COUT(1) << ex.what() << std::endl; 136 167 } 137 168 } … … 151 182 FunctorMember<T>* savefunction_; 152 183 }; 184 185 186 // ################################ 187 // ### XMLPortObjectContainer ### 188 // ################################ 189 class _CoreExport XMLPortObjectContainer 190 { 191 public: 192 XMLPortObjectContainer(); 193 194 inline const std::string& getName() const 195 { return this->sectionname_; } 196 197 XMLPortObjectContainer& description(const std::string description); 198 const std::string& getDescription(); 199 200 protected: 201 std::string classname_; 202 std::string sectionname_; 203 204 private: 205 LanguageEntryLabel description_; 206 bool bAddedDescription_; 207 }; 208 209 template <class T, class O> 210 class XMLPortClassObjectContainer : public XMLPortObjectContainer 211 { 212 public: 213 XMLPortClassObjectContainer(const std::string classname, const std::string sectionname, void (T::*loadfunction)(O*), const O* (T::*savefunction)(unsigned int)) 214 { 215 this->classname_ = classname; 216 this->sectionname_ = sectionname; 217 this->loadfunction_ = loadfunction; 218 this->savefunction_ = savefunction; 219 } 220 221 XMLPortObjectContainer& port(T* object, Element& xmlelement, bool loading) 222 { 223 if (loading) 224 { 225 try 226 { 227 Element* xmlsubelement = xmlelement.FirstChildElement(this->sectionname_, false); 228 229 if (xmlsubelement) 230 { 231 for ( ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++ ) 232 { 233 Identifier* identifier = ID(child->Value()); 234 if (identifier) 235 { 236 if (identifier->isA(Class(O))) 237 { 238 if (Loader::currentMask_s.isIncluded(identifier)) 239 { 240 COUT(4) << object->getLoaderIndentation() << "fabricating " << child->Value() << "..." << std::endl; 241 O* newObject = (O*)identifier->fabricate(); 242 newObject->setLoaderIndentation(object->getLoaderIndentation() + " "); 243 newObject->setLevel(object->getLevel()); 244 newObject->XMLPort(*child, true); 245 COUT(4) << object->getLoaderIndentation() << "assigning " << child->Value() << " (objectname " << newObject->getName() << ") to " << this->classname_ << " (objectname " << object->getName() << ")" << std::endl; 246 (*object.*this->loadfunction_)(newObject); 247 COUT(5) << " ...fabricated " << child->Value() << " (objectname " << newObject->getName() << ")." << std::endl; 248 } 249 } 250 else 251 { 252 COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not a '" << Class(O)->getName() << "'." << std::endl; 253 } 254 } 255 else 256 { 257 COUT(2) << object->getLoaderIndentation() << "Warning: '" << child->Value() << "' is not a valid classname." << std::endl; 258 } 259 } 260 } 261 } 262 catch(ticpp::Exception& ex) 263 { 264 COUT(1) << std::endl; 265 COUT(1) << "An error occurred in XMLPort.h while loading a '" << Class(O)->getName() << "' in '" << this->sectionname_ << "' of '" << this->classname_ << "' (objectname: " << object->getName() << ") in " << object->getLevelfile() << ":" << std::endl; 266 COUT(1) << ex.what() << std::endl; 267 } 268 } 269 else 270 { 271 } 272 273 return (*this); 274 } 275 276 private: 277 void (T::*loadfunction_)(O*); 278 const O* (T::*savefunction_)(unsigned int); 279 }; 153 280 } 154 281 -
code/branches/core/src/orxonox/objects/WorldEntity.cc
r853 r856 167 167 Element& WorldEntity::XMLPort(Element& xmlelement, bool loading) 168 168 { 169 std::cout << "2_1: " << this->getPosition() << std::endl;170 169 BaseObject::XMLPort(xmlelement, loading); 171 170 … … 178 177 XMLPortParam(WorldEntity, "rotationAxis", setRotationAxis, getRotationAxis, xmlelement, loading); 179 178 XMLPortParam(WorldEntity, "rotationRate", setRotationRate, getRotationRate, xmlelement, loading); 180 std::cout << "2_2: " << this->getPosition() << std::endl; 179 180 XMLPortObject(WorldEntity, WorldEntity, "attached", attachWorldEntity, getAttachedWorldEntity, xmlelement, loading); 181 181 182 182 return xmlelement; … … 210 210 registerVar( (void*) &(this->getRotationAxis().z), sizeof(this->getRotationAxis().z), network::DATA);*/ 211 211 } 212 213 void WorldEntity::attachWorldEntity(WorldEntity* entity) 214 { 215 this->attachedWorldEntities_.push_back(entity); 216 } 217 218 const WorldEntity* WorldEntity::getAttachedWorldEntity(unsigned int index) 219 { 220 if (index < this->attachedWorldEntities_.size()) 221 return this->attachedWorldEntities_[index]; 222 else 223 return 0; 224 } 212 225 } -
code/branches/core/src/orxonox/objects/WorldEntity.h
r853 r856 27 27 virtual Element& XMLPort(Element& xmlelement, bool loading); 28 28 bool create(); 29 30 void attachWorldEntity(WorldEntity* entity); 31 const WorldEntity* getAttachedWorldEntity(unsigned int index); 29 32 30 33 inline Ogre::SceneNode* getNode() … … 156 159 Ogre::SceneNode* node_; 157 160 bool bStatic_; 161 std::vector<WorldEntity*> attachedWorldEntities_; 158 162 }; 159 163 }
Note: See TracChangeset
for help on using the changeset viewer.