- Timestamp:
- Oct 5, 2009, 5:02:25 PM (15 years ago)
- Location:
- code/branches/core5/src
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core5/src/libraries/core/BaseObject.cc
r5866 r5879 63 63 this->bVisible_ = true; 64 64 this->oldGametype_ = 0; 65 this->bRegisteredEventStates_ = false; 65 66 66 67 this->lastLoadedXMLElement_ = 0; 67 68 68 this->functorSetMainState_ = 0; 69 this->functorGetMainState_ = 0; 69 this->mainStateFunctor_ = 0; 70 70 71 71 this->setCreator(creator); … … 100 100 (*(it++))->removeEventSource(this); 101 101 102 for (std::map<std::string, Event Container*>::const_iterator it = this->eventContainers_.begin(); it != this->eventContainers_.end(); ++it)102 for (std::map<std::string, EventState*>::const_iterator it = this->eventStates_.begin(); it != this->eventStates_.end(); ++it) 103 103 delete it->second; 104 105 if (this->functorSetMainState_)106 delete this->functorSetMainState_;107 if (this->functorGetMainState_)108 delete this->functorGetMainState_;109 104 } 110 105 } … … 114 109 @param xmlelement The XML-element 115 110 @param loading Loading (true) or saving (false) 116 @return The XML-element117 111 */ 118 112 void BaseObject::XMLPort(Element& xmlelement, XMLPort::Mode mode) … … 124 118 125 119 XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*); 126 127 Element* events = xmlelement.FirstChildElement("events", false); 128 120 121 Element* events = 0; 122 if (mode == XMLPort::LoadObject || mode == XMLPort::ExpandObject) 123 events = xmlelement.FirstChildElement("events", false); 124 else if (mode == XMLPort::SaveObject) 125 ; 129 126 if (events) 130 { 131 std::list<std::string> eventnames; 132 133 if (mode == XMLPort::LoadObject || mode == XMLPort::ExpandObject) 134 { 135 for (ticpp::Iterator<ticpp::Element> child = events->FirstChildElement(false); child != child.end(); child++) 136 eventnames.push_back(child->Value()); 137 } 138 else if (mode == XMLPort::SaveObject) 139 { 140 for (std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->getIdentifier()->getXMLPortEventMapBegin(); it != this->getIdentifier()->getXMLPortEventMapEnd(); ++it) 141 eventnames.push_back(it->first); 142 } 143 144 for (std::list<std::string>::iterator it = eventnames.begin(); it != eventnames.end(); ++it) 145 { 146 std::string sectionname = (*it); 147 ExecutorMember<BaseObject>* loadexecutor = createExecutor(createFunctor(&BaseObject::addEventSource), std::string( "BaseObject" ) + "::" + "addEventSource"); 148 ExecutorMember<BaseObject>* saveexecutor = createExecutor(createFunctor(&BaseObject::getEventSource), std::string( "BaseObject" ) + "::" + "getEventSource"); 149 loadexecutor->setDefaultValue(1, sectionname); 150 saveexecutor->setDefaultValue(1, sectionname); 151 152 XMLPortClassObjectContainer<BaseObject, BaseObject>* container = 0; 153 container = static_cast<XMLPortClassObjectContainer<BaseObject, BaseObject>*>(this->getIdentifier()->getXMLPortEventContainer(sectionname)); 154 if (!container) 155 { 156 container = new XMLPortClassObjectContainer<BaseObject, BaseObject>(sectionname, this->getIdentifier(), loadexecutor, saveexecutor, false, true); 157 this->getIdentifier()->addXMLPortEventContainer(sectionname, container); 158 } 159 container->port(this, *events, mode); 160 } 161 } 127 this->XMLEventPort(*events, mode); 128 } 129 130 /** 131 @brief Defines the possible event states of this object and parses eventsources from an XML file. 132 @param xmlelement The XML-element 133 @param loading Loading (true) or saving (false) 134 */ 135 void BaseObject::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) 136 { 137 XMLPortEventState(BaseObject, BaseObject, "activity", setActive, xmlelement, mode); 138 XMLPortEventState(BaseObject, BaseObject, "visibility", setVisible, xmlelement, mode); 139 140 this->bRegisteredEventStates_ = true; 162 141 } 163 142 … … 263 242 } 264 243 265 void BaseObject::addEvent Container(const std::string& sectionname, EventContainer* container)266 { 267 std::map<std::string, Event Container*>::const_iterator it = this->eventContainers_.find(sectionname);268 if (it != this->event Containers_.end())269 { 270 COUT(2) << "Warning: Overwriting Event Containerin class " << this->getIdentifier()->getName() << "." << std::endl;244 void BaseObject::addEventState(const std::string& name, EventState* state) 245 { 246 std::map<std::string, EventState*>::const_iterator it = this->eventStates_.find(name); 247 if (it != this->eventStates_.end()) 248 { 249 COUT(2) << "Warning: Overwriting EventState in class " << this->getIdentifier()->getName() << "." << std::endl; 271 250 delete (it->second); 272 251 } 273 252 274 this->event Containers_[sectionname] = container;275 } 276 277 Event Container* BaseObject::getEventContainer(const std::string& sectionname) const278 { 279 std::map<std::string, Event Container*>::const_iterator it = this->eventContainers_.find(sectionname);280 if (it != this->event Containers_.end())253 this->eventStates_[name] = state; 254 } 255 256 EventState* BaseObject::getEventState(const std::string& name) const 257 { 258 std::map<std::string, EventState*>::const_iterator it = this->eventStates_.find(name); 259 if (it != this->eventStates_.end()) 281 260 return ((*it).second); 282 261 else … … 302 281 303 282 /** 304 @brief Fires an event which activates or deactivates a state with agiven originator (the object which sendsthe event).283 @brief Fires an event which activates or deactivates a state with agiven originator (the object which triggered the event). 305 284 */ 306 285 void BaseObject::fireEvent(bool activate, BaseObject* originator) … … 310 289 for (std::set<BaseObject*>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 311 290 { 312 event.s ectionname_ = (*it)->eventSources_[this];291 event.statename_ = (*it)->eventSources_[this]; 313 292 (*it)->processEvent(event); 314 293 } … … 324 303 } 325 304 305 /** 306 @brief Processing an event by calling the right main state. 307 @param event The event struct which contains the information about the event 308 */ 326 309 void BaseObject::processEvent(Event& event) 327 310 { 328 ORXONOX_SET_EVENT(BaseObject, "activity", setActive, event); 329 ORXONOX_SET_EVENT(BaseObject, "visibility", setVisible, event); 330 } 331 332 void BaseObject::setMainStateName(const std::string& name) 333 { 334 if (this->mainStateName_ != name) 335 { 336 this->mainStateName_ = name; 337 if (this->functorSetMainState_) 338 delete this->functorSetMainState_; 339 if (this->functorGetMainState_) 340 delete this->functorGetMainState_; 341 this->changedMainState(); 342 if (!this->functorSetMainState_) 343 COUT(2) << "Warning: \"" << name << "\" is not a valid MainState." << std::endl; 344 } 345 } 346 311 this->registerEventStates(); 312 313 std::map<std::string, EventState*>::const_iterator it = this->eventStates_.find(event.statename_); 314 if (it != this->eventStates_.end()) 315 it->second->process(event, this); 316 else if (event.statename_ != "") 317 COUT(2) << "Warning: \"" << event.statename_ << "\" is not a valid state in object \"" << this->getName() << "\" of class " << this->getIdentifier()->getName() << "." << std::endl; 318 else 319 COUT(2) << "Warning: Event with invalid source sent to object \"" << this->getName() << "\" of class " << this->getIdentifier()->getName() << "." << std::endl; 320 } 321 322 /** 323 @brief Sets the main state of the object to a given boolean value. 324 325 Note: The main state of an object can be set with the @ref setMainStateName function. 326 It's part of the eventsystem and used for event forwarding (when the target object can't specify a specific state, 327 the main state is used by default). 328 */ 347 329 void BaseObject::setMainState(bool state) 348 330 { 349 if (this-> functorSetMainState_)350 (*this-> functorSetMainState_)(state);331 if (this->mainStateFunctor_) 332 (*this->mainStateFunctor_)(state); 351 333 else 352 334 COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl; 353 335 } 354 336 355 bool BaseObject::getMainState() const 356 { 357 if (this->functorGetMainState_) 358 { 359 (*this->functorGetMainState_)(); 360 return this->functorGetMainState_->getReturnvalue(); 361 } 362 else 363 { 364 COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl; 365 return false; 366 } 367 } 368 369 void BaseObject::changedMainState() 370 { 371 SetMainState(BaseObject, "activity", setActive, isActive); 372 SetMainState(BaseObject, "visibility", setVisible, isVisible); 337 /** 338 @brief This function gets called if the main state name of the object changes. 339 */ 340 void BaseObject::changedMainStateName() 341 { 342 this->registerEventStates(); 343 344 this->mainStateFunctor_ = 0; 345 346 std::map<std::string, EventState*>::const_iterator it = this->eventStates_.find(this->mainStateName_); 347 if (it != this->eventStates_.end() && it->second->getFunctor() && it->second->getFunctor()->getParamCount() == 1) 348 this->mainStateFunctor_ = it->second->getFunctor(); 349 else 350 COUT(2) << "Warning: \"" << this->mainStateName_ << "\" is not a valid MainState." << std::endl; 351 } 352 353 /** 354 @brief Calls XMLEventPort with an empty XML-element to register the event states if necessary. 355 */ 356 void BaseObject::registerEventStates() 357 { 358 if (!this->bRegisteredEventStates_) 359 { 360 Element xmlelement; 361 this->XMLEventPort(xmlelement, XMLPort::NOP); 362 } 373 363 } 374 364 } -
code/branches/core5/src/libraries/core/BaseObject.h
r5866 r5879 37 37 #define _BaseObject_H__ 38 38 39 #define SetMainState(classname, statename, setfunction, getfunction) \40 if (this->getMainStateName() == statename) \41 { \42 this->functorSetMainState_ = createFunctor(&classname::setfunction, this); \43 this->functorGetMainState_ = createFunctor(&classname::getfunction, this); \44 }45 46 47 39 #include "CorePrereqs.h" 48 40 … … 69 61 virtual ~BaseObject(); 70 62 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 63 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); 71 64 72 65 /** @brief Returns if the object was initialized (passed the object registration). @return True was the object is initialized */ … … 111 104 112 105 void setMainState(bool state); 113 bool getMainState() const; 114 115 void setMainStateName(const std::string& name); 106 107 /** @brief Sets the name of the main state (used for event reactions). */ 108 void setMainStateName(const std::string& name) 109 { 110 if (this->mainStateName_ != name) 111 { 112 this->mainStateName_ = name; 113 this->changedMainStateName(); 114 } 115 } 116 /** @brief Returns the name of the main state. */ 116 117 inline const std::string& getMainStateName() const { return this->mainStateName_; } 117 virtual void changedMainState(); 118 /** @brief This function gets called if the main state name of the object changes. */ 119 virtual void changedMainStateName(); 118 120 119 121 /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */ … … 176 178 { this->eventListeners_.erase(object); } 177 179 178 void addEvent Container(const std::string& sectionname, EventContainer* container);179 Event Container* getEventContainer(const std::string& sectionname) const;180 void addEventState(const std::string& name, EventState* container); 181 EventState* getEventState(const std::string& name) const; 180 182 181 183 std::string name_; //!< The name of the object … … 184 186 mbool bVisible_; //!< True = the object is visible 185 187 std::string mainStateName_; 186 Functor* functorSetMainState_; 187 Functor* functorGetMainState_; 188 Functor* mainStateFunctor_; 188 189 189 190 private: 190 191 void setXMLName(const std::string& name); 191 192 Template* getTemplate(unsigned int index) const; 193 void registerEventStates(); 192 194 193 195 bool bInitialized_; //!< True if the object was initialized (passed the object registration) … … 204 206 std::set<Template*> templates_; 205 207 206 std::map<BaseObject*, std::string> eventSources_; //!< List of objects which send events to this object, mapped to the state which they affect 207 std::set<BaseObject*> eventListeners_; //!< List of objects which listen to the events of this object 208 std::map<std::string, EventContainer*> eventContainers_; 208 std::map<BaseObject*, std::string> eventSources_; //!< List of objects which send events to this object, mapped to the state which they affect 209 std::set<BaseObject*> eventListeners_; //!< List of objects which listen to the events of this object 210 std::map<std::string, EventState*> eventStates_; //!< Maps the name of the event states to their helper objects 211 bool bRegisteredEventStates_; //!< Becomes true after the object registered its event states (with XMLEventPort) 209 212 }; 210 213 … … 212 215 SUPER_FUNCTION(2, BaseObject, changedActivity, false); 213 216 SUPER_FUNCTION(3, BaseObject, changedVisibility, false); 214 SUPER_FUNCTION(4, BaseObject, processEvent, false); 215 SUPER_FUNCTION(6, BaseObject, changedMainState, false); 216 SUPER_FUNCTION(9, BaseObject, changedName, false); 217 SUPER_FUNCTION(10, BaseObject, changedGametype, false); 217 SUPER_FUNCTION(4, BaseObject, XMLEventPort, false); 218 SUPER_FUNCTION(8, BaseObject, changedName, false); 219 SUPER_FUNCTION(9, BaseObject, changedGametype, false); 218 220 } 219 221 -
code/branches/core5/src/libraries/core/CorePrereqs.h
r5863 r5879 77 77 enum Mode 78 78 { 79 NOP, 79 80 LoadObject, 80 81 SaveObject, … … 130 131 class DynLibManager; 131 132 struct Event; 132 class Event Container;133 class EventState; 133 134 class Executor; 134 135 template <class T> -
code/branches/core5/src/libraries/core/Event.cc
r5866 r5879 30 30 31 31 #include "BaseObject.h" 32 #include "Identifier.h" 32 33 33 34 namespace orxonox 34 35 { 35 EventContainer::~EventContainer() 36 /** 37 @brief Destructor: Deletes the functor of the event state. 38 */ 39 EventState::~EventState() 36 40 { 37 delete this->eventfunction_; 41 if (this->statefunction_) 42 delete this->statefunction_; 38 43 } 39 44 40 void EventContainer::process(BaseObject* object, const Event& event) 45 /** 46 @brief Processes an event (calls the set-function if the necessary conditions are met). 47 48 @param event The fired event 49 @param object The object whose state is affected by the event (only needed for debug output) 50 */ 51 void EventState::process(const Event& event, BaseObject* object) 41 52 { 42 if (this->b Active_)53 if (this->bProcessingEvent_) 43 54 { 44 COUT(2) << "Warning: Detected Event loop in section \"" << this->eventname_ << "\" of object \"" << object->getName() << "\" and fired by \"" << event.originator_->getName() << "\"" << std::endl;55 COUT(2) << "Warning: Detected Event loop in section \"" << event.statename_ << "\" of object \"" << object->getName() << "\" and fired by \"" << event.originator_->getName() << "\"" << std::endl; 45 56 return; 46 57 } 47 58 48 this->b Active_ = true;59 this->bProcessingEvent_ = true; 49 60 50 if (this->eventname_ == event.sectionname_) 61 // check if the originator is an instance of the requested class 62 if (event.originator_->isA(this->subclass_)) 51 63 { 52 if (event.originator_->isA(this->subclass_)) 64 // actualize the activationcounter 65 if (event.activate_) 66 ++this->activeEvents_; 67 else 53 68 { 54 if (event.activate_) 55 ++this->activeEvents_; 56 else 69 --this->activeEvents_; 70 71 if (this->activeEvents_ < 0) 72 this->activeEvents_ = 0; 73 } 74 75 if (this->statefunction_->getParamCount() == 0 && event.activate_) 76 { 77 // if the eventfunction doesn't have a state, just call it whenever an activation-event comes in 78 (*this->statefunction_)(); 79 } 80 else if ((this->activeEvents_ == 1 && event.activate_) || (this->activeEvents_ == 0 && !event.activate_)) 81 { 82 // if the eventfunction needs a state, we just call the function if the state changed from 0 to 1 (state = true) or from 1 to 0 (state = false) [but not if activeEvents_ is > 1] 83 if (this->statefunction_->getParamCount() == 1) 57 84 { 58 --this->activeEvents_; 59 60 if (this->activeEvents_ < 0) 61 this->activeEvents_ = 0; 85 // one argument: just the eventstate 86 (*this->statefunction_)(this->activeEvents_); 62 87 } 63 64 if (this->eventfunction_->getParamCount() == 0 && event.activate_) 65 (*this->eventfunction_)(); 66 else if ((this->activeEvents_ == 1 && event.activate_) || (this->activeEvents_ == 0 && !event.activate_)) 88 else if (this->statefunction_->getParamCount() >= 2) 67 89 { 68 if (this->eventfunction_->getParamCount() == 1) 69 (*this->eventfunction_)(this->activeEvents_); 70 else if (this->eventfunction_->getParamCount() >= 2 && event.castedOriginator_) 71 (*this->eventfunction_)(this->activeEvents_, event.castedOriginator_); 90 // two arguments: the eventstate and the originator 91 if (this->subclass_->isExactlyA(ClassIdentifier<BaseObject>::getIdentifier())) 92 { 93 // if the subclass is BaseObject, we don't have to cast the pointer 94 (*this->statefunction_)(this->activeEvents_, event.originator_); 95 } 96 else 97 { 98 // else cast the pointer to the desired class 99 void* castedOriginator = event.originator_->getDerivedPointer(this->subclass_->getClassID()); 100 (*this->statefunction_)(this->activeEvents_, castedOriginator); 101 } 72 102 } 73 103 } 74 104 } 75 105 76 this->b Active_ = false;106 this->bProcessingEvent_ = false; 77 107 } 78 108 } -
code/branches/core5/src/libraries/core/Event.h
r5866 r5879 35 35 namespace orxonox 36 36 { 37 /** 38 @brief The Event struct contains information about a fired Event. 39 */ 37 40 struct _CoreExport Event 38 41 { 39 Event(bool activate, BaseObject* originator) : activate_(activate), originator_(originator), castedOriginator_(0) {}42 Event(bool activate, BaseObject* originator) : activate_(activate), originator_(originator) {} 40 43 41 bool activate_; 42 BaseObject* originator_; 43 void* castedOriginator_; 44 std::string sectionname_; 44 bool activate_; //!< True if this is an activating event (the event source was inactive before and just triggered the event) - false otherwise 45 std::string statename_; //!< The name of the state this event affects 46 BaseObject* originator_; //!< The object which triggered this event 45 47 }; 46 48 47 class _CoreExport EventContainer 49 /** 50 @brief The EventState contains information about an event state. 51 52 An event state is a state of an object, which can be changed by events. 53 Event states are changed through functions. Possible functions headers for set event states are: 54 - memoryless state: function() 55 - boolean state: function(bool state) 56 - individual state: function(bool state, SomeClass originator) 57 58 Note that SomeClass may be any class deriving from BaseObject. You will not receive events from originators of other classes. 59 The actual class for SomeClass must be specified as the second argument of the XMLPortEventState macro. 60 61 The this pointer of the affected object is hidden in the functors, because the events are processed in the BaseObject, but some 62 statefunctions may be from child-classes. 63 */ 64 class _CoreExport EventState 48 65 { 49 66 public: 50 Event Container(const std::string& eventname, Functor* eventfunction, Identifier* subclass) : bActive_(false), eventname_(eventname), eventfunction_(eventfunction), subclass_(subclass), activeEvents_(0) {}51 virtual ~Event Container();67 EventState(Functor* statefunction, Identifier* subclass) : bProcessingEvent_(false), activeEvents_(0), statefunction_(statefunction), subclass_(subclass) {} 68 virtual ~EventState(); 52 69 53 void process(BaseObject* object, const Event& event); 70 void process(const Event& event, BaseObject* object); 71 72 Functor* getFunctor() const 73 { return this->statefunction_; } 54 74 55 75 private: 56 bool bActive_; 57 std::string eventname_; 58 Functor* eventfunction_; 59 Identifier* subclass_; 60 61 int activeEvents_; 76 bool bProcessingEvent_; //!< This becomes true while the container processes an event (used to prevent loops) 77 int activeEvents_; //!< The number of events which affect this state and are currently active 78 Functor* statefunction_; //!< A functor to set the state 79 Identifier* subclass_; //!< Originators must be an instance of this class (usually BaseObject, but some statefunctions allow a second argument with an originator of a specific class) 62 80 }; 63 81 } -
code/branches/core5/src/libraries/core/EventIncludes.h
r5866 r5879 33 33 #include "Executor.h" 34 34 35 #define ORXONOX_SET_EVENT(classname, eventname, functionname, event) \ 36 ORXONOX_SET_EVENT_GENERIC(eventcontainer##classname##functionname, classname, eventname, functionname, event, BaseObject) 35 /** 36 @brief Defines a new event state (a state of the object which can be changed by events). 37 38 @param classname The name of this class 39 @param subclassname Usually BaseObject - if different, only instances of this class can send events to this object 40 @param statename The name (string) of this state 41 @param function The function which should be used to set the state 42 @param xmlelement Argument for XMLPort 43 @param mode Argument for XMLPort 44 */ 45 #define XMLPortEventState(classname, subclassname, statename, function, xmlelement, mode) \ 46 orxonox::EventState* containername##function = this->getEventState(statename); \ 47 if (!containername##function) \ 48 { \ 49 containername##function = new orxonox::EventState(orxonox::createFunctor(&classname::function, this), orxonox::ClassIdentifier<subclassname>::getIdentifier()); \ 50 this->addEventState(statename, containername##function); \ 51 } \ 52 XMLPortEventStateIntern(xmlportevent##function, classname, statename, xmlelement, mode) 37 53 38 #define ORXONOX_SET_EVENT_TEMPLATE(classname, eventname, functionname, event, ...) \ 39 ORXONOX_SET_EVENT_GENERIC_TEMPLATE(eventcontainer##classname##functionname, classname, eventname, functionname, event, BaseObject, __VA_ARGS__) 54 /** 55 @brief Like XMLPortEventState but with additional template arguments to identify the function of the state (if ambiguous). 56 */ 57 #define XMLPortEventStateTemplate(classname, subclassname, statename, function, xmlelement, mode, ...) \ 58 orxonox::EventState* containername##function = this->getEventState(statename); \ 59 if (!containername##function) \ 60 { \ 61 containername##function = new orxonox::EventState(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::function, this), orxonox::ClassIdentifier<subclassname>::getIdentifier()); \ 62 this->addEventState(statename, containername##function); \ 63 } \ 64 XMLPortEventStateIntern(xmlportevent##function, classname, statename, xmlelement, mode) 40 65 41 #define ORXONOX_SET_SUBCLASS_EVENT(classname, eventname, functionname, event, subclassname) \ 42 event.castedOriginator_ = orxonox::orxonox_cast<subclassname*>(event.originator_); \ 43 ORXONOX_SET_EVENT_GENERIC(eventcontainer##classname##functionname, classname, eventname, functionname, event, subclassname) 44 45 #define ORXONOX_SET_SUBCLASS_EVENT_TEMPLATE(classname, eventname, functionname, event, subclassname, ...) \ 46 event.castedOriginator_ = orxonox::orxonox_cast<subclassname*>(event.originator_); \ 47 ORXONOX_SET_EVENT_GENERIC_TEMPLATE(eventcontainer##classname##functionname, classname, eventname, functionname, event, subclassname, __VA_ARGS__) 48 49 #define ORXONOX_SET_EVENT_GENERIC(containername, classname, eventname, functionname, event, subclassname) \ 50 orxonox::EventContainer* containername = this->getEventContainer(eventname); \ 51 if (!containername) \ 52 { \ 53 Functor* functor = orxonox::createFunctor(&classname::functionname, this); \ 54 containername = new orxonox::EventContainer(std::string(eventname), functor, orxonox::ClassIdentifier<subclassname>::getIdentifier()); \ 55 this->addEventContainer(eventname, containername); \ 56 } \ 57 containername->process(this, event) 58 59 #define ORXONOX_SET_EVENT_GENERIC_TEMPLATE(containername, classname, eventname, functionname, event, subclassname, ...) \ 60 orxonox::EventContainer* containername = this->getEventContainer(eventname); \ 61 if (!containername) \ 62 { \ 63 Functor* functor = orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::functionname, this); \ 64 containername = new orxonox::EventContainer(std::string(eventname), functor, orxonox::ClassIdentifier<subclassname>::getIdentifier()); \ 65 this->addEventContainer(eventname, containername); \ 66 } \ 67 containername->process(this, event) 68 66 #define XMLPortEventStateIntern(name, classname, statename, xmlelement, mode) \ 67 static orxonox::ExecutorMember<classname>* xmlsetfunctor##name = (orxonox::ExecutorMember<classname>*)&orxonox::createExecutor(orxonox::createFunctor(&classname::addEventSource), std::string( #classname ) + "::" + "addEventSource" + "(" + statename + ")")->setDefaultValue(1, statename); \ 68 static orxonox::ExecutorMember<classname>* xmlgetfunctor##name = (orxonox::ExecutorMember<classname>*)&orxonox::createExecutor(orxonox::createFunctor(&classname::getEventSource), std::string( #classname ) + "::" + "getEventSource" + "(" + statename + ")")->setDefaultValue(1, statename); \ 69 XMLPortObjectGeneric(xmlport##name, classname, orxonox::BaseObject, statename, xmlsetfunctor##name, xmlgetfunctor##name, xmlelement, mode, false, true) 70 69 71 #endif /* _EventIncludes_H__ */ -
code/branches/core5/src/libraries/core/Identifier.cc
r5821 r5879 87 87 delete (it->second); 88 88 for (std::map<std::string, XMLPortObjectContainer*>::iterator it = this->xmlportObjectContainers_.begin(); it != this->xmlportObjectContainers_.end(); ++it) 89 delete (it->second);90 for (std::map<std::string, XMLPortObjectContainer*>::iterator it = this->xmlportEventContainers_.begin(); it != this->xmlportEventContainers_.end(); ++it)91 89 delete (it->second); 92 90 } … … 565 563 566 564 /** 567 @brief Returns a XMLPortEventContainer that attaches an event to this class.568 @param sectionname The name of the section that contains the event569 @return The container570 */571 XMLPortObjectContainer* Identifier::getXMLPortEventContainer(const std::string& eventname)572 {573 std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportEventContainers_.find(eventname);574 if (it != this->xmlportEventContainers_.end())575 return it->second;576 else577 return 0;578 }579 580 /**581 @brief Adds a new XMLPortEventContainer that attaches an event to this class.582 @param sectionname The name of the section that contains the event583 @param container The container584 */585 void Identifier::addXMLPortEventContainer(const std::string& eventname, XMLPortObjectContainer* container)586 {587 std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportEventContainers_.find(eventname);588 if (it != this->xmlportEventContainers_.end())589 {590 COUT(2) << "Warning: Overwriting XMLPortEventContainer in class " << this->getName() << "." << std::endl;591 delete (it->second);592 }593 594 this->xmlportEventContainers_[eventname] = container;595 }596 597 /**598 565 @brief Lists the names of all Identifiers in a std::set<const Identifier*>. 599 566 @param out The outstream -
code/branches/core5/src/libraries/core/Identifier.h
r5866 r5879 268 268 269 269 270 //////////////////271 ///// Events /////272 //////////////////273 /** @brief Returns the map that stores all XMLPort events. @return The const_iterator */274 inline const std::map<std::string, XMLPortObjectContainer*>& getXMLPortEventMap() const { return this->xmlportEventContainers_; }275 /** @brief Returns a const_iterator to the beginning of the map that stores all XMLPort events. @return The const_iterator */276 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortEventMapBegin() const { return this->xmlportEventContainers_.begin(); }277 /** @brief Returns a const_iterator to the end of the map that stores all XMLPort events. @return The const_iterator */278 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortEventMapEnd() const { return this->xmlportEventContainers_.end(); }279 280 void addXMLPortEventContainer(const std::string& eventname, XMLPortObjectContainer* container);281 XMLPortObjectContainer* getXMLPortEventContainer(const std::string& eventname);282 283 284 270 protected: 285 271 Identifier(); … … 342 328 std::map<std::string, XMLPortParamContainer*> xmlportParamContainers_; //!< All loadable parameters 343 329 std::map<std::string, XMLPortObjectContainer*> xmlportObjectContainers_; //!< All attachable objects 344 std::map<std::string, XMLPortObjectContainer*> xmlportEventContainers_; //!< All events345 330 }; 346 331 -
code/branches/core5/src/libraries/core/OrxonoxClass.h
r5823 r5879 110 110 Returns NULL if the no pointer was found. 111 111 */ 112 template <class T> 113 FORCEINLINE T* getDerivedPointer(unsigned int classID) 112 FORCEINLINE void* getDerivedPointer(unsigned int classID) 114 113 { 115 114 for (int i = this->objectPointers_.size() - 1; i >= 0; --i) 116 115 { 117 116 if (this->objectPointers_[i].first == classID) 118 return static_cast<T*>(this->objectPointers_[i].second);117 return this->objectPointers_[i].second; 119 118 } 120 119 return NULL; 121 120 } 122 //! Const version of getDerivedPointer 123 template <class T> 124 FORCEINLINE const T* getDerivedPointer(unsigned int classID) const 125 { 126 return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID); 127 } 121 122 //! Version of getDerivedPointer with template 123 template <class T> FORCEINLINE T* getDerivedPointer(unsigned int classID) 124 { return static_cast<T*>(this->getDerivedPointer(classID)); } 125 //! Const version of getDerivedPointer with template 126 template <class T> FORCEINLINE const T* getDerivedPointer(unsigned int classID) const 127 { return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID); } 128 128 129 129 private: -
code/branches/core5/src/libraries/core/Super.h
r5738 r5879 250 250 SUPER_NOARGS(classname, functionname) 251 251 252 #define SUPER_ processEvent(classname, functionname, ...) \252 #define SUPER_XMLEventPort(classname, functionname, ...) \ 253 253 SUPER_ARGS(classname, functionname, __VA_ARGS__) 254 254 255 255 #define SUPER_changedScale(classname, functionname, ...) \ 256 SUPER_NOARGS(classname, functionname)257 258 #define SUPER_changedMainState(classname, functionname, ...) \259 256 SUPER_NOARGS(classname, functionname) 260 257 … … 497 494 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 498 495 499 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(4, processEvent, true, Event& event)500 ( event)496 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(4, XMLEventPort, true, Element& xmlelement, XMLPort::Mode mode) 497 (xmlelement, mode) 501 498 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 502 499 … … 505 502 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 506 503 507 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(6, changedMainState, false) 508 () 509 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 510 511 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(7, changedOwner, false) 512 () 513 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 514 515 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(8, changedOverlayGroup, false) 516 () 517 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 518 519 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(9, changedName, false) 520 () 521 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 522 523 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(10, changedGametype, false) 504 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(6, changedOwner, false) 505 () 506 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 507 508 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(7, changedOverlayGroup, false) 509 () 510 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 511 512 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(8, changedName, false) 513 () 514 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 515 516 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(9, changedGametype, false) 524 517 () 525 518 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; … … 571 564 SUPER_INTRUSIVE_DECLARATION(changedActivity); 572 565 SUPER_INTRUSIVE_DECLARATION(changedVisibility); 573 SUPER_INTRUSIVE_DECLARATION( processEvent);566 SUPER_INTRUSIVE_DECLARATION(XMLEventPort); 574 567 SUPER_INTRUSIVE_DECLARATION(changedScale); 575 SUPER_INTRUSIVE_DECLARATION(changedMainState);576 568 SUPER_INTRUSIVE_DECLARATION(changedOwner); 577 569 SUPER_INTRUSIVE_DECLARATION(changedOverlayGroup); -
code/branches/core5/src/libraries/core/XMLPort.h
r5858 r5879 411 411 } 412 412 } 413 else 413 else if (mode == XMLPort::SaveObject) 414 414 { 415 415 if (this->saveexecutor_) … … 628 628 } 629 629 } 630 else 630 else if (mode == XMLPort::SaveObject) 631 631 { 632 632 } -
code/branches/core5/src/modules/objects/Attacher.cc
r5738 r5879 53 53 void Attacher::processEvent(Event& event) 54 54 { 55 for (std::list<WorldEntity*>::iterator it = this->objects_.begin(); it != this->objects_.end(); ++it)56 (*it)->fireEvent(event);55 if (this->target_) 56 this->target_->processEvent(event); 57 57 } 58 58 … … 102 102 103 103 for (ObjectList<WorldEntity>::iterator it = ObjectList<WorldEntity>::begin(); it != ObjectList<WorldEntity>::end(); ++it) 104 { 104 105 if (it->getName() == this->targetname_) 106 { 107 this->target_ = *it; 105 108 this->attachToParent(*it); 109 } 110 } 106 111 } 107 112 -
code/branches/core5/src/modules/objects/triggers/EventTrigger.cc
r5738 r5879 47 47 } 48 48 49 void EventTrigger:: processEvent(Event& event)49 void EventTrigger::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) 50 50 { 51 SUPER(EventTrigger, processEvent, event);51 SUPER(EventTrigger, XMLEventPort, xmlelement, mode); 52 52 53 ORXONOX_SET_EVENT(EventTrigger, "trigger", trigger, event);53 XMLPortEventState(EventTrigger, BaseObject, "trigger", trigger, xmlelement, mode); 54 54 } 55 55 -
code/branches/core5/src/modules/objects/triggers/EventTrigger.h
r5738 r5879 41 41 virtual ~EventTrigger(); 42 42 43 virtual void processEvent(Event& event);43 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); 44 44 45 45 inline void trigger(bool bTriggered) -
code/branches/core5/src/modules/questsystem/QuestEffectBeacon.cc
r5738 r5879 75 75 XMLPortObject(QuestEffectBeacon, QuestEffect, "effects", addEffect, getEffect, xmlelement, mode); 76 76 77 XMLPortEventState(QuestEffectBeacon, PlayerTrigger, "execute", execute, xmlelement, mode); 78 77 79 COUT(3) << "New QuestEffectBeacon created." << std::endl; 78 80 } 79 81 80 /** 81 @brief 82 Processes an event for this QuestEffectBeacon. 83 */ 84 void QuestEffectBeacon::processEvent(Event& event) 85 { 86 SUPER(QuestEffectBeacon, processEvent, event); 87 88 ORXONOX_SET_SUBCLASS_EVENT(QuestEffectBeacon, "execute", execute, event, PlayerTrigger); 82 void QuestEffectBeacon::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) 83 { 84 SUPER(QuestEffectBeacon, XMLEventPort, xmlelement, mode); 85 86 XMLPortEventState(QuestEffectBeacon, PlayerTrigger, "execute", execute, xmlelement, mode); 89 87 } 90 88 -
code/branches/core5/src/modules/questsystem/QuestEffectBeacon.h
r5738 r5879 86 86 87 87 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a QuestEffectBeacon object through XML. 88 89 virtual void processEvent(Event& event); //!< Processes an event for this QuestEffectBeacon. 88 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); 90 89 91 90 bool execute(bool b, PlayerTrigger* trigger); //!< Executes the QuestEffects of the QuestEffectBeacon. -
code/branches/core5/src/orxonox/graphics/ParticleSpawner.cc
r5857 r5879 71 71 } 72 72 73 void ParticleSpawner:: processEvent(Event& event)73 void ParticleSpawner::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) 74 74 { 75 SUPER(ParticleSpawner, processEvent, event);75 SUPER(ParticleSpawner, XMLEventPort, xmlelement, mode); 76 76 77 ORXONOX_SET_EVENT(ParticleSpawner, "spawn", spawn, event);77 XMLPortEventState(ParticleSpawner, BaseObject, "spawn", spawn, xmlelement, mode); 78 78 } 79 79 -
code/branches/core5/src/orxonox/graphics/ParticleSpawner.h
r5831 r5879 44 44 45 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 virtual void processEvent(Event& event);46 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); 47 47 48 48 inline void stop(bool bDestroy) -
code/branches/core5/src/orxonox/overlays/OrxonoxOverlay.h
r3327 r5879 213 213 }; 214 214 215 SUPER_FUNCTION( 7, OrxonoxOverlay, changedOwner, false);216 SUPER_FUNCTION( 8, OrxonoxOverlay, changedOverlayGroup, false);215 SUPER_FUNCTION(6, OrxonoxOverlay, changedOwner, false); 216 SUPER_FUNCTION(7, OrxonoxOverlay, changedOverlayGroup, false); 217 217 } 218 218 -
code/branches/core5/src/orxonox/worldentities/WorldEntity.cc
r5801 r5879 175 175 void WorldEntity::registerVariables() 176 176 { 177 registerVariable(this->mainStateName_, VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedMainState ));177 registerVariable(this->mainStateName_, VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedMainStateName)); 178 178 179 179 registerVariable(this->bActive_, VariableDirection::ToClient, new NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity));
Note: See TracChangeset
for help on using the changeset viewer.