Changeset 2254 for code/branches/objecthierarchy2/src/core
- Timestamp:
- Nov 24, 2008, 1:50:47 AM (16 years ago)
- Location:
- code/branches/objecthierarchy2/src/core
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy2/src/core/BaseObject.cc
r2173 r2254 36 36 #include "CoreIncludes.h" 37 37 #include "EventIncludes.h" 38 #include "Functor.h" 38 39 #include "XMLPort.h" 39 40 #include "XMLFile.h" … … 60 61 this->oldGametype_ = 0; 61 62 63 this->functorSetMainState_ = 0; 64 this->functorGetMainState_ = 0; 65 62 66 this->setCreator(creator); 63 67 if (this->creator_) … … 82 86 BaseObject::~BaseObject() 83 87 { 84 for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it) 85 (*it)->unregisterEventListener(this); 86 87 for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 88 it->first->removeEvent(this); 88 if (this->isInitialized()) 89 { 90 for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it) 91 (*it)->unregisterEventListener(this); 92 93 for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 94 it->first->removeEvent(this); 95 96 if (this->functorSetMainState_) 97 delete this->functorSetMainState_; 98 if (this->functorGetMainState_) 99 delete this->functorGetMainState_; 100 } 89 101 } 90 102 … … 100 112 XMLPortParam(BaseObject, "visible", setVisible, isVisible, xmlelement, mode); 101 113 XMLPortParam(BaseObject, "active", setActive, isActive, xmlelement, mode); 114 XMLPortParam(BaseObject, "mainstate", setMainStateName, getMainStateName, xmlelement, mode); 102 115 103 116 XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*); … … 279 292 SetEvent(BaseObject, "visibility", setVisible, event); 280 293 } 294 295 void BaseObject::setMainStateName(const std::string& name) 296 { 297 if (this->mainStateName_ != name) 298 { 299 this->mainStateName_ = name; 300 if (this->functorSetMainState_) 301 delete this->functorSetMainState_; 302 if (this->functorGetMainState_) 303 delete this->functorGetMainState_; 304 this->changedMainState(); 305 if (!this->functorSetMainState_) 306 COUT(2) << "Warning: \"" << name << "\" is not a valid MainState." << std::endl; 307 } 308 } 309 310 void BaseObject::setMainState(bool state) 311 { 312 if (this->functorSetMainState_) 313 (*this->functorSetMainState_)(state); 314 else 315 COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl; 316 } 317 318 bool BaseObject::getMainState() const 319 { 320 if (this->functorGetMainState_) 321 { 322 (*this->functorGetMainState_)(); 323 return this->functorGetMainState_->getReturnvalue(); 324 } 325 else 326 { 327 COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl; 328 return false; 329 } 330 } 331 332 void BaseObject::changedMainState() 333 { 334 SetMainState(BaseObject, "activity", setActive, isActive); 335 SetMainState(BaseObject, "visibility", setVisible, isVisible); 336 } 281 337 } -
code/branches/objecthierarchy2/src/core/BaseObject.h
r2171 r2254 36 36 #ifndef _BaseObject_H__ 37 37 #define _BaseObject_H__ 38 39 #define SetMainState(classname, statename, setfunction, getfunction) \ 40 if (this->getMainStateName() == statename) \ 41 { \ 42 this->functorSetMainState_ = createFunctor(&classname::setfunction)->setObject(this); \ 43 this->functorGetMainState_ = createFunctor(&classname::getfunction)->setObject(this); \ 44 } 38 45 39 46 #include <map> … … 100 107 virtual void changedVisibility() {} 101 108 109 void setMainState(bool state); 110 bool getMainState() const; 111 112 void setMainStateName(const std::string& name); 113 inline const std::string& getMainStateName() const { return this->mainStateName_; } 114 virtual void changedMainState(); 115 102 116 /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */ 103 117 inline void setFile(const XMLFile* file) { this->file_ = file; } … … 153 167 std::string name_; //!< The name of the object 154 168 std::string oldName_; //!< The old name of the object 155 mbool bActive_; //!< True = the object is active 156 mbool bVisible_; //!< True = the object is visible 169 mbool bActive_; //!< True = the object is active 170 mbool bVisible_; //!< True = the object is visible 171 std::string mainStateName_; 172 Functor* functorSetMainState_; 173 Functor* functorGetMainState_; 157 174 158 175 private: … … 160 177 Template* getTemplate(unsigned int index) const; 161 178 162 bool bInitialized_; //!< True if the object was initialized (passed the object registration)163 const XMLFile* file_; //!< The XMLFile that loaded this object164 std::string loaderIndentation_; //!< Indentation of the debug output in the Loader165 Namespace* namespace_;166 BaseObject* creator_;167 Scene* scene_;168 Gametype* gametype_;169 Gametype* oldGametype_;170 std::set<Template*> templates_;171 std::map<BaseObject*, std::string> eventListeners_;179 bool bInitialized_; //!< True if the object was initialized (passed the object registration) 180 const XMLFile* file_; //!< The XMLFile that loaded this object 181 std::string loaderIndentation_; //!< Indentation of the debug output in the Loader 182 Namespace* namespace_; 183 BaseObject* creator_; 184 Scene* scene_; 185 Gametype* gametype_; 186 Gametype* oldGametype_; 187 std::set<Template*> templates_; 188 std::map<BaseObject*, std::string> eventListeners_; 172 189 std::list<BaseObject*> events_; 173 190 std::map<std::string, EventContainer*> eventContainers_; … … 178 195 SUPER_FUNCTION(3, BaseObject, changedVisibility, false); 179 196 SUPER_FUNCTION(4, BaseObject, processEvent, false); 197 SUPER_FUNCTION(6, BaseObject, changedMainState, false); 180 198 } 181 199 -
code/branches/objecthierarchy2/src/core/Functor.h
r2087 r2254 167 167 } 168 168 169 FunctorMember * setObject(T* object)169 FunctorMember<T>* setObject(T* object) 170 170 { 171 171 this->bConstObject_ = false; … … 174 174 } 175 175 176 FunctorMember * setObject(const T* object)176 FunctorMember<T>* setObject(const T* object) 177 177 { 178 178 this->bConstObject_ = true; -
code/branches/objecthierarchy2/src/core/Super.h
r2212 r2254 236 236 #define SUPER_changedScale(classname, functionname, ...) \ 237 237 SUPER_NOARGS(classname, functionname) 238 239 #define SUPER_changedMainState(classname, functionname, ...) \ 240 SUPER_NOARGS(classname, functionname) 238 241 // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 239 242 … … 448 451 () 449 452 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 453 454 SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(6, changedMainState, false) 455 () 456 SUPER_FUNCTION_GLOBAL_DECLARATION_PART2; 450 457 // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 451 458 … … 496 503 SUPER_INTRUSIVE_DECLARATION(processEvent); 497 504 SUPER_INTRUSIVE_DECLARATION(changedScale); 505 SUPER_INTRUSIVE_DECLARATION(changedMainState); 498 506 // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- 499 507
Note: See TracChangeset
for help on using the changeset viewer.