Changeset 2063 for code/branches/objecthierarchy/src/core
- Timestamp:
- Oct 29, 2008, 6:39:31 PM (16 years ago)
- Location:
- code/branches/objecthierarchy/src/core
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/core/BaseObject.cc
r2019 r2063 94 94 95 95 XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*); 96 97 Element* events = xmlelement.FirstChildElement("events", false); 98 99 if (events) 100 { 101 std::list<std::string> eventnames; 102 103 if (mode == XMLPort::LoadObject) 104 { 105 for (ticpp::Iterator<ticpp::Element> child = events->FirstChildElement(false); child != child.end(); child++) 106 eventnames.push_back(child->Value()); 107 } 108 else if (mode == XMLPort::SaveObject) 109 { 110 for (std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->getIdentifier()->getXMLPortEventMapBegin(); it != this->getIdentifier()->getXMLPortEventMapEnd(); ++it) 111 eventnames.push_back(it->first); 112 } 113 114 for (std::list<std::string>::iterator it = eventnames.begin(); it != eventnames.end(); ++it) 115 { 116 std::string sectionname = (*it); 117 ExecutorMember<BaseObject>* loadexecutor = createExecutor(createFunctor(&BaseObject::addEvent), std::string( "BaseObject" ) + "::" + "addEvent"); 118 ExecutorMember<BaseObject>* saveexecutor = createExecutor(createFunctor(&BaseObject::getEvent), std::string( "BaseObject" ) + "::" + "getEvent"); 119 loadexecutor->setDefaultValue(1, sectionname); 120 121 XMLPortClassObjectContainer<BaseObject, BaseObject>* container = 0; 122 container = (XMLPortClassObjectContainer<BaseObject, BaseObject>*)(this->getIdentifier()->getXMLPortEventContainer(sectionname)); 123 if (!container) 124 { 125 container = new XMLPortClassObjectContainer<BaseObject, BaseObject>(sectionname, this->getIdentifier(), loadexecutor, saveexecutor, false, true); 126 this->getIdentifier()->addXMLPortEventContainer(sectionname, container); 127 } 128 container->port(this, *events, mode); 129 } 130 } 96 131 } 97 132 … … 146 181 return 0; 147 182 } 183 184 void BaseObject::addEvent(BaseObject* event, const std::string& sectionname) 185 { 186 this->eventListeners_.insert(std::pair<std::string, BaseObject*>(sectionname, event)); 187 } 188 189 BaseObject* BaseObject::getEvent(unsigned int index) const 190 { 191 unsigned int i = 0; 192 for (std::set<std::pair<std::string, BaseObject*> >::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 193 { 194 if (i == index) 195 return (*it).second; 196 ++i; 197 } 198 return 0; 199 } 200 201 void BaseObject::addEventContainer(const std::string& sectionname, EventContainer* container) 202 { 203 std::map<std::string, EventContainer*>::const_iterator it = this->eventContainers_.find(sectionname); 204 if (it != this->eventContainers_.end()) 205 { 206 COUT(2) << "Warning: Overwriting EventContainer in class " << this->getIdentifier()->getName() << "." << std::endl; 207 delete (it->second); 208 } 209 210 this->eventContainers_[sectionname] = container; 211 } 212 213 EventContainer* BaseObject::getEventContainer(const std::string& sectionname) const 214 { 215 std::map<std::string, EventContainer*>::const_iterator it = this->eventContainers_.begin(); 216 if (it != this->eventContainers_.end()) 217 return ((*it).second); 218 else 219 return 0; 220 } 221 222 void BaseObject::fireEvent() 223 { 224 this->fireEvent(true); 225 this->fireEvent(false); 226 } 227 228 void BaseObject::fireEvent(bool activate) 229 { 230 Event event(activate, this); 231 232 for (std::set<std::pair<std::string, BaseObject*> >::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 233 { 234 event.sectionname_ = (*it).first; 235 (*it).second->processEvent(event); 236 } 237 } 238 239 void BaseObject::processEvent(Event& event) 240 { 241 SetEvent(BaseObject, "activity", setActive, event); 242 SetEvent(BaseObject, "visibility", setVisible, event); 243 } 148 244 } -
code/branches/objecthierarchy/src/core/BaseObject.h
r2019 r2063 42 42 #include "OrxonoxClass.h" 43 43 #include "XMLIncludes.h" 44 #include "Event.h" 44 45 45 46 namespace orxonox … … 110 111 virtual inline void changedGametype() {} 111 112 113 void fireEvent(); 114 void fireEvent(bool activate); 115 116 virtual void processEvent(Event& event); 117 118 void addEvent(BaseObject* event, const std::string& sectionname); 119 BaseObject* getEvent(unsigned int index) const; 120 121 void addEventContainer(const std::string& sectionname, EventContainer* container); 122 EventContainer* getEventContainer(const std::string& sectionname) const; 123 112 124 /** @brief Sets the indentation of the debug output in the Loader. @param indentation The indentation */ 113 125 inline void setLoaderIndentation(const std::string& indentation) { this->loaderIndentation_ = indentation; } … … 124 136 Template* getTemplate(unsigned int index) const; 125 137 126 bool bInitialized_; //!< True if the object was initialized (passed the object registration) 127 const XMLFile* file_; //!< The XMLFile that loaded this object 128 std::string loaderIndentation_; //!< Indentation of the debug output in the Loader 129 Namespace* namespace_; 130 BaseObject* creator_; 131 Scene* scene_; 132 Gametype* gametype_; 133 Gametype* oldGametype_; 134 std::set<Template*> templates_; 138 bool bInitialized_; //!< True if the object was initialized (passed the object registration) 139 const XMLFile* file_; //!< The XMLFile that loaded this object 140 std::string loaderIndentation_; //!< Indentation of the debug output in the Loader 141 Namespace* namespace_; 142 BaseObject* creator_; 143 Scene* scene_; 144 Gametype* gametype_; 145 Gametype* oldGametype_; 146 std::set<Template*> templates_; 147 std::set<std::pair<std::string, BaseObject*> > eventListeners_; 148 std::map<std::string, EventContainer*> eventContainers_; 135 149 }; 136 150 … … 138 152 SUPER_FUNCTION(2, BaseObject, changedActivity, false); 139 153 SUPER_FUNCTION(3, BaseObject, changedVisibility, false); 154 SUPER_FUNCTION(4, BaseObject, processEvent, false); 140 155 } 141 156 -
code/branches/objecthierarchy/src/core/CMakeLists.txt
r1989 r2063 4 4 ConfigValueContainer.cc 5 5 Core.cc 6 Event.cc 6 7 GameState.cc 7 8 Language.cc -
code/branches/objecthierarchy/src/core/CorePrereqs.h
r2010 r2063 113 113 class ConsoleCommand; 114 114 class Core; 115 struct Event; 116 class EventContainer; 115 117 class Executor; 116 118 template <class T> -
code/branches/objecthierarchy/src/core/Identifier.cc
r2019 r2063 421 421 XMLPortParamContainer* Identifier::getXMLPortParamContainer(const std::string& paramname) 422 422 { 423 std::map<std::string, XMLPortParamContainer*>::const_iterator it = xmlportParamContainers_.find(paramname);424 if (it != xmlportParamContainers_.end())423 std::map<std::string, XMLPortParamContainer*>::const_iterator it = this->xmlportParamContainers_.find(paramname); 424 if (it != this->xmlportParamContainers_.end()) 425 425 return ((*it).second); 426 426 else … … 435 435 void Identifier::addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) 436 436 { 437 std::map<std::string, XMLPortParamContainer*>::const_iterator it = this->xmlportParamContainers_.find(paramname); 438 if (it != this->xmlportParamContainers_.end()) 439 { 440 COUT(2) << "Warning: Overwriting XMLPortParamContainer in class " << this->getName() << "." << std::endl; 441 delete (it->second); 442 } 443 437 444 this->xmlportParamContainers_[paramname] = container; 438 445 } … … 445 452 XMLPortObjectContainer* Identifier::getXMLPortObjectContainer(const std::string& sectionname) 446 453 { 447 std::map<std::string, XMLPortObjectContainer*>::const_iterator it = xmlportObjectContainers_.find(sectionname);448 if (it != xmlportObjectContainers_.end())454 std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportObjectContainers_.find(sectionname); 455 if (it != this->xmlportObjectContainers_.end()) 449 456 return ((*it).second); 450 457 else … … 459 466 void Identifier::addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) 460 467 { 468 std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportObjectContainers_.find(sectionname); 469 if (it != this->xmlportObjectContainers_.end()) 470 { 471 COUT(2) << "Warning: Overwriting XMLPortObjectContainer in class " << this->getName() << "." << std::endl; 472 delete (it->second); 473 } 474 461 475 this->xmlportObjectContainers_[sectionname] = container; 476 } 477 478 /** 479 @brief Returns a XMLPortEventContainer that attaches an event to this class. 480 @param sectionname The name of the section that contains the event 481 @return The container 482 */ 483 XMLPortObjectContainer* Identifier::getXMLPortEventContainer(const std::string& eventname) 484 { 485 std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportEventContainers_.find(eventname); 486 if (it != this->xmlportEventContainers_.end()) 487 return ((*it).second); 488 else 489 return 0; 490 } 491 492 /** 493 @brief Adds a new XMLPortEventContainer that attaches an event to this class. 494 @param sectionname The name of the section that contains the event 495 @param container The container 496 */ 497 void Identifier::addXMLPortEventContainer(const std::string& eventname, XMLPortObjectContainer* container) 498 { 499 std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportEventContainers_.find(eventname); 500 if (it != this->xmlportEventContainers_.end()) 501 { 502 COUT(2) << "Warning: Overwriting XMLPortEventContainer in class " << this->getName() << "." << std::endl; 503 delete (it->second); 504 } 505 506 this->xmlportEventContainers_[eventname] = container; 462 507 } 463 508 -
code/branches/objecthierarchy/src/core/Identifier.h
r2024 r2063 210 210 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapEnd() const { return this->xmlportObjectContainers_.end(); } 211 211 212 /** @brief Returns the map that stores all XMLPort events. @return The const_iterator */ 213 inline const std::map<std::string, XMLPortObjectContainer*>& getXMLPortEventMap() const { return this->xmlportEventContainers_; } 214 /** @brief Returns a const_iterator to the beginning of the map that stores all XMLPort events. @return The const_iterator */ 215 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortEventMapBegin() const { return this->xmlportEventContainers_.begin(); } 216 /** @brief Returns a const_iterator to the end of the map that stores all XMLPort events. @return The const_iterator */ 217 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortEventMapEnd() const { return this->xmlportEventContainers_.end(); } 218 212 219 /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */ 213 220 inline bool hasConfigValues() const { return this->bHasConfigValues_; } … … 233 240 void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container); 234 241 XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname); 242 243 void addXMLPortEventContainer(const std::string& eventname, XMLPortObjectContainer* container); 244 XMLPortObjectContainer* getXMLPortEventContainer(const std::string& eventname); 235 245 236 246 ConsoleCommand& addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut); … … 307 317 std::map<std::string, XMLPortParamContainer*> xmlportParamContainers_; //!< All loadable parameters 308 318 std::map<std::string, XMLPortObjectContainer*> xmlportObjectContainers_; //!< All attachable objects 319 std::map<std::string, XMLPortObjectContainer*> xmlportEventContainers_; //!< All events 309 320 }; 310 321 -
code/branches/objecthierarchy/src/core/Super.h
r1841 r2063 73 73 #include "util/Debug.h" 74 74 #include "XMLIncludes.h" 75 #include "Event.h" 75 76 76 77 /////////////////////// … … 229 230 #define SUPER_changedVisibility(classname, functionname, ...) \ 230 231 SUPER_NOARGS(classname, functionname) 232 233 #define SUPER_processEvent(classname, functionname, ...) \ 234 SUPER_ARGS(classname, functionname, __VA_ARGS__) 231 235 // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 232 236 … … 433 437 () 434 438 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 439 440 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(4, processEvent, true, Event& event) 441 (event) 442 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 435 443 // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 436 444 … … 479 487 SUPER_INTRUSIVE_DECLARATION(changedActivity); 480 488 SUPER_INTRUSIVE_DECLARATION(changedVisibility); 489 SUPER_INTRUSIVE_DECLARATION(processEvent); 481 490 // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 482 491
Note: See TracChangeset
for help on using the changeset viewer.