Changeset 5929 for code/trunk/src/libraries
- Timestamp:
- Oct 12, 2009, 8:20:07 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 6 deleted
- 87 edited
- 11 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core5 (added) merged: 5768-5769,5772,5775-5780,5783-5785,5791-5792,5795-5807,5809-5814,5816-5832,5836-5839,5842-5853,5855-5899,5904-5922,5924-5928
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/CMakeLists.txt
r5781 r5929 25 25 ################ Sub Directories ################ 26 26 27 ADD_SUBDIRECTORY(util) 27 28 ADD_SUBDIRECTORY(core) 28 29 ADD_SUBDIRECTORY(network) 29 30 ADD_SUBDIRECTORY(tools) 30 ADD_SUBDIRECTORY(util) -
code/trunk/src/libraries/core/ArgumentCompletionFunctions.cc
r5781 r5929 100 100 ArgumentCompletionList classlist; 101 101 102 for (std::map<std::string, Identifier*>::const_iterator it = Identifier::get IdentifierMapBegin(); it != Identifier::getIdentifierMapEnd(); ++it)102 for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapBegin(); it != Identifier::getStringIdentifierMapEnd(); ++it) 103 103 if ((*it).second->hasConfigValues()) 104 104 classlist.push_back(ArgumentCompletionListElement((*it).second->getName(), getLowercase((*it).first))); … … 110 110 { 111 111 ArgumentCompletionList configvalues; 112 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::get IdentifierMap().find(classname);112 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getStringIdentifierMap().find(classname); 113 113 114 if (identifier != Identifier::get IdentifierMapEnd() && (*identifier).second->hasConfigValues())114 if (identifier != Identifier::getStringIdentifierMapEnd() && (*identifier).second->hasConfigValues()) 115 115 { 116 116 for (std::map<std::string, ConfigValueContainer*>::const_iterator it = (*identifier).second->getConfigValueMapBegin(); it != (*identifier).second->getConfigValueMapEnd(); ++it) … … 124 124 { 125 125 ArgumentCompletionList oldvalue; 126 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercase IdentifierMap().find(getLowercase(classname));127 if (identifier != Identifier::getLowercase IdentifierMapEnd())126 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname)); 127 if (identifier != Identifier::getLowercaseStringIdentifierMapEnd()) 128 128 { 129 129 std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname)); -
code/trunk/src/libraries/core/BaseObject.cc
r5781 r5929 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); … … 74 74 this->setFile(this->creator_->getFile()); 75 75 this->setNamespace(this->creator_->getNamespace()); 76 this->setScene(this->creator_->getScene() );76 this->setScene(this->creator_->getScene(), this->creator_->getSceneID()); 77 77 this->setGametype(this->creator_->getGametype()); 78 78 } … … 82 82 this->namespace_ = 0; 83 83 this->scene_ = 0; 84 this->sceneID_ = OBJECTID_UNKNOWN; 84 85 this->gametype_ = 0; 85 86 } … … 93 94 if (this->isInitialized()) 94 95 { 95 for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it) 96 (*it)->unregisterEventListener(this); 97 98 for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 99 it->first->removeEvent(this); 100 101 if (this->functorSetMainState_) 102 delete this->functorSetMainState_; 103 if (this->functorGetMainState_) 104 delete this->functorGetMainState_; 96 for (std::map<BaseObject*, std::string>::const_iterator it = this->eventSources_.begin(); it != this->eventSources_.end(); ) 97 this->removeEventSource((it++)->first); 98 99 for (std::set<BaseObject*>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ) 100 (*(it++))->removeEventSource(this); 101 102 for (std::map<std::string, EventState*>::const_iterator it = this->eventStates_.begin(); it != this->eventStates_.end(); ++it) 103 delete it->second; 105 104 } 106 105 } … … 110 109 @param xmlelement The XML-element 111 110 @param loading Loading (true) or saving (false) 112 @return The XML-element113 111 */ 114 112 void BaseObject::XMLPort(Element& xmlelement, XMLPort::Mode mode) … … 120 118 121 119 XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*); 122 123 Element* events = xmlelement.FirstChildElement("events", false); 124 120 XMLPortObject(BaseObject, BaseObject, "eventlisteners", addEventListener, getEventListener, xmlelement, mode); 121 122 Element* events = 0; 123 if (mode == XMLPort::LoadObject || mode == XMLPort::ExpandObject) 124 events = xmlelement.FirstChildElement("events", false); 125 else if (mode == XMLPort::SaveObject) 126 {} 125 127 if (events) 126 { 127 std::list<std::string> eventnames; 128 129 if (mode == XMLPort::LoadObject || mode == XMLPort::ExpandObject) 130 { 131 for (ticpp::Iterator<ticpp::Element> child = events->FirstChildElement(false); child != child.end(); child++) 132 eventnames.push_back(child->Value()); 133 } 134 else if (mode == XMLPort::SaveObject) 135 { 136 for (std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->getIdentifier()->getXMLPortEventMapBegin(); it != this->getIdentifier()->getXMLPortEventMapEnd(); ++it) 137 eventnames.push_back(it->first); 138 } 139 140 for (std::list<std::string>::iterator it = eventnames.begin(); it != eventnames.end(); ++it) 141 { 142 std::string sectionname = (*it); 143 ExecutorMember<BaseObject>* loadexecutor = createExecutor(createFunctor(&BaseObject::addEvent), std::string( "BaseObject" ) + "::" + "addEvent"); 144 ExecutorMember<BaseObject>* saveexecutor = createExecutor(createFunctor(&BaseObject::getEvent), std::string( "BaseObject" ) + "::" + "getEvent"); 145 loadexecutor->setDefaultValue(1, sectionname); 146 147 XMLPortClassObjectContainer<BaseObject, BaseObject>* container = 0; 148 container = (XMLPortClassObjectContainer<BaseObject, BaseObject>*)(this->getIdentifier()->getXMLPortEventContainer(sectionname)); 149 if (!container) 150 { 151 container = new XMLPortClassObjectContainer<BaseObject, BaseObject>(sectionname, this->getIdentifier(), loadexecutor, saveexecutor, false, true); 152 this->getIdentifier()->addXMLPortEventContainer(sectionname, container); 153 } 154 container->port(this, *events, mode); 155 } 156 } 128 this->XMLEventPort(*events, mode); 129 } 130 131 /** 132 @brief Defines the possible event states of this object and parses eventsources from an XML file. 133 @param xmlelement The XML-element 134 @param loading Loading (true) or saving (false) 135 */ 136 void BaseObject::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) 137 { 138 XMLPortEventState(BaseObject, BaseObject, "activity", setActive, xmlelement, mode); 139 XMLPortEventState(BaseObject, BaseObject, "visibility", setVisible, xmlelement, mode); 140 XMLPortEventState(BaseObject, BaseObject, "mainstate", setMainState, xmlelement, mode); 141 142 this->bRegisteredEventStates_ = true; 157 143 } 158 144 … … 220 206 } 221 207 222 void BaseObject::addEvent(BaseObject* event, const std::string& sectionname) 223 { 224 event->registerEventListener(this, sectionname); 225 this->events_.push_back(event); 226 } 227 228 void BaseObject::removeEvent(BaseObject* event) 229 { 230 this->events_.remove(event); 231 } 232 233 BaseObject* BaseObject::getEvent(unsigned int index) const 208 /** 209 @brief Adds a new event source for a specific state. 210 @param source The object which sends events to this object 211 @param state The state of this object which will be affected by the events 212 */ 213 void BaseObject::addEventSource(BaseObject* source, const std::string& state) 214 { 215 this->eventSources_[source] = state; 216 source->registerEventListener(this); 217 } 218 219 /** 220 @brief Removes an eventsource (but doesn't unregister itself at the source). 221 */ 222 void BaseObject::removeEventSource(BaseObject* source) 223 { 224 this->eventSources_.erase(source); 225 source->unregisterEventListener(this); 226 } 227 228 /** 229 @brief Returns an eventsource with a given index. 230 */ 231 BaseObject* BaseObject::getEventSource(unsigned int index, const std::string& state) const 234 232 { 235 233 unsigned int i = 0; 236 for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it) 237 { 234 for (std::map<BaseObject*, std::string>::const_iterator it = this->eventSources_.begin(); it != this->eventSources_.end(); ++it) 235 { 236 if (it->second != state) 237 continue; 238 238 239 if (i == index) 239 return (*it);240 return it->first; 240 241 ++i; 241 242 } … … 243 244 } 244 245 245 void BaseObject::addEventContainer(const std::string& sectionname, EventContainer* container) 246 { 247 std::map<std::string, EventContainer*>::const_iterator it = this->eventContainers_.find(sectionname); 248 if (it != this->eventContainers_.end()) 249 { 250 COUT(2) << "Warning: Overwriting EventContainer in class " << this->getIdentifier()->getName() << "." << std::endl; 246 /** 247 @brief Adds an object which listens to the events of this object. The events are sent to the other objects mainstate. 248 */ 249 void BaseObject::addEventListener(BaseObject* listener) 250 { 251 this->eventListenersXML_.insert(listener); 252 listener->addEventSource(this, "mainstate"); 253 } 254 255 /** 256 @brief Returns an event listener with a given index. 257 */ 258 BaseObject* BaseObject::getEventListener(unsigned int index) const 259 { 260 unsigned int i = 0; 261 for (std::set<BaseObject*>::const_iterator it = this->eventListenersXML_.begin(); it != this->eventListenersXML_.end(); ++it) 262 { 263 if (i == index) 264 return *it; 265 ++i; 266 } 267 return 0; 268 } 269 270 /** 271 @brief Adds a new event-state to the object. Event-states are states which can be changed by events. 272 @param name The name of the event 273 @param state The object containing information about the event-state 274 */ 275 void BaseObject::addEventState(const std::string& name, EventState* state) 276 { 277 std::map<std::string, EventState*>::const_iterator it = this->eventStates_.find(name); 278 if (it != this->eventStates_.end()) 279 { 280 COUT(2) << "Warning: Overwriting EventState in class " << this->getIdentifier()->getName() << "." << std::endl; 251 281 delete (it->second); 252 282 } 253 283 254 this->eventContainers_[sectionname] = container; 255 } 256 257 EventContainer* BaseObject::getEventContainer(const std::string& sectionname) const 258 { 259 std::map<std::string, EventContainer*>::const_iterator it = this->eventContainers_.find(sectionname); 260 if (it != this->eventContainers_.end()) 284 this->eventStates_[name] = state; 285 } 286 287 /** 288 @brief Returns the event-state with the given name. 289 */ 290 EventState* BaseObject::getEventState(const std::string& name) const 291 { 292 std::map<std::string, EventState*>::const_iterator it = this->eventStates_.find(name); 293 if (it != this->eventStates_.end()) 261 294 return ((*it).second); 262 295 else … … 264 297 } 265 298 266 void BaseObject::fireEvent() 267 { 268 this->fireEvent(true); 269 this->fireEvent(false); 270 } 271 272 void BaseObject::fireEvent(bool activate) 273 { 274 this->fireEvent(activate, this); 275 } 276 277 void BaseObject::fireEvent(bool activate, BaseObject* originator) 278 { 279 Event event(activate, originator); 280 281 for (std::map<BaseObject*, std::string>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 282 { 283 event.sectionname_ = it->second; 284 it->first->processEvent(event); 285 } 286 } 287 299 /** 300 @brief Fires an event (without a state). 301 */ 302 void BaseObject::fireEvent(const std::string& name) 303 { 304 this->fireEvent(true, name); 305 this->fireEvent(false, name); 306 } 307 308 /** 309 @brief Fires an event which activates or deactivates a state. 310 */ 311 void BaseObject::fireEvent(bool activate, const std::string& name) 312 { 313 this->fireEvent(activate, this, name); 314 } 315 316 /** 317 @brief Fires an event which activates or deactivates a state with agiven originator (the object which triggered the event). 318 */ 319 void BaseObject::fireEvent(bool activate, BaseObject* originator, const std::string& name) 320 { 321 Event event(activate, originator, name); 322 323 for (std::set<BaseObject*>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 324 { 325 event.statename_ = (*it)->eventSources_[this]; 326 (*it)->processEvent(event); 327 } 328 } 329 330 /** 331 @brief Fires an event, using the Event struct. 332 */ 288 333 void BaseObject::fireEvent(Event& event) 289 334 { 290 for (std::map<BaseObject*, std::string>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 291 it->first->processEvent(event); 292 } 293 335 for (std::set<BaseObject*>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 336 (*it)->processEvent(event); 337 } 338 339 /** 340 @brief Processing an event by calling the right main state. 341 @param event The event struct which contains the information about the event 342 */ 294 343 void BaseObject::processEvent(Event& event) 295 344 { 296 ORXONOX_SET_EVENT(BaseObject, "activity", setActive, event); 297 ORXONOX_SET_EVENT(BaseObject, "visibility", setVisible, event); 298 } 299 300 void BaseObject::setMainStateName(const std::string& name) 301 { 302 if (this->mainStateName_ != name) 303 { 304 this->mainStateName_ = name; 305 if (this->functorSetMainState_) 306 delete this->functorSetMainState_; 307 if (this->functorGetMainState_) 308 delete this->functorGetMainState_; 309 this->changedMainState(); 310 if (!this->functorSetMainState_) 311 COUT(2) << "Warning: \"" << name << "\" is not a valid MainState." << std::endl; 312 } 313 } 314 345 this->registerEventStates(); 346 347 std::map<std::string, EventState*>::const_iterator it = this->eventStates_.find(event.statename_); 348 if (it != this->eventStates_.end()) 349 it->second->process(event, this); 350 else if (event.statename_ != "") 351 COUT(2) << "Warning: \"" << event.statename_ << "\" is not a valid state in object \"" << this->getName() << "\" of class " << this->getIdentifier()->getName() << "." << std::endl; 352 else 353 COUT(2) << "Warning: Event with invalid source sent to object \"" << this->getName() << "\" of class " << this->getIdentifier()->getName() << "." << std::endl; 354 } 355 356 /** 357 @brief Sets the main state of the object to a given boolean value. 358 359 Note: The main state of an object can be set with the @ref setMainStateName function. 360 It's part of the eventsystem and used for event forwarding (when the target object can't specify a specific state, 361 the main state is used by default). 362 */ 315 363 void BaseObject::setMainState(bool state) 316 364 { 317 if (this->functorSetMainState_) 318 (*this->functorSetMainState_)(state); 365 if (this->mainStateFunctor_) 366 { 367 if (this->mainStateFunctor_->getParamCount() == 0) 368 { 369 if (state) 370 (*this->mainStateFunctor_)(); 371 } 372 else 373 { 374 (*this->mainStateFunctor_)(state); 375 } 376 } 319 377 else 320 378 COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl; 321 379 } 322 380 323 bool BaseObject::getMainState() const 324 { 325 if (this->functorGetMainState_) 326 { 327 (*this->functorGetMainState_)(); 328 return this->functorGetMainState_->getReturnvalue(); 329 } 330 else 331 { 332 COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl; 333 return false; 334 } 335 } 336 337 void BaseObject::changedMainState() 338 { 339 SetMainState(BaseObject, "activity", setActive, isActive); 340 SetMainState(BaseObject, "visibility", setVisible, isVisible); 381 /** 382 @brief This function gets called if the main state name of the object changes. 383 */ 384 void BaseObject::changedMainStateName() 385 { 386 this->mainStateFunctor_ = 0; 387 388 if (this->mainStateName_ != "") 389 { 390 this->registerEventStates(); 391 392 std::map<std::string, EventState*>::const_iterator it = this->eventStates_.find(this->mainStateName_); 393 if (it != this->eventStates_.end() && it->second->getFunctor()) 394 { 395 if (it->second->getFunctor()->getParamCount() <= 1) 396 this->mainStateFunctor_ = it->second->getFunctor(); 397 else 398 COUT(2) << "Warning: Can't use \"" << this->mainStateName_ << "\" as MainState because it needs a second argument." << std::endl; 399 } 400 else 401 COUT(2) << "Warning: \"" << this->mainStateName_ << "\" is not a valid MainState." << std::endl; 402 } 403 } 404 405 /** 406 @brief Calls XMLEventPort with an empty XML-element to register the event states if necessary. 407 */ 408 void BaseObject::registerEventStates() 409 { 410 if (!this->bRegisteredEventStates_) 411 { 412 Element xmlelement; 413 this->XMLEventPort(xmlelement, XMLPort::NOP); 414 } 415 } 416 417 /** 418 @brief Manually loads all event states, even if the class doesn't officially support them. This is needed by some classes like @ref EventDispatcher or @ref EventTarget. 419 */ 420 void BaseObject::loadAllEventStates(Element& xmlelement, XMLPort::Mode mode, BaseObject* object, Identifier* identifier) 421 { 422 Element* events = xmlelement.FirstChildElement("events", false); 423 if (events) 424 { 425 // get the list of all states present 426 std::list<std::string> eventnames; 427 if (mode == XMLPort::LoadObject || mode == XMLPort::ExpandObject) 428 { 429 for (ticpp::Iterator<ticpp::Element> child = events->FirstChildElement(false); child != child.end(); child++) 430 eventnames.push_back(child->Value()); 431 } 432 else if (mode == XMLPort::SaveObject) 433 { 434 } 435 436 // iterate through all states and get the event sources 437 for (std::list<std::string>::iterator it = eventnames.begin(); it != eventnames.end(); ++it) 438 { 439 std::string statename = (*it); 440 441 // if the event state is already known, continue with the next state 442 orxonox::EventState* eventstate = object->getEventState(statename); 443 if (eventstate) 444 continue; 445 446 XMLPortClassObjectContainer<BaseObject, BaseObject>* container = (XMLPortClassObjectContainer<BaseObject, BaseObject>*)(identifier->getXMLPortObjectContainer(statename)); 447 if (!container) 448 { 449 ExecutorMember<BaseObject>* setfunctor = createExecutor(createFunctor(&BaseObject::addEventSource), std::string( "BaseObject" ) + "::" + "addEventSource" + "(" + statename + ")"); 450 ExecutorMember<BaseObject>* getfunctor = createExecutor(createFunctor(&BaseObject::getEventSource), std::string( "BaseObject" ) + "::" + "getEventSource" + "(" + statename + ")"); 451 setfunctor->setDefaultValue(1, statename); 452 getfunctor->setDefaultValue(1, statename); 453 454 container = new XMLPortClassObjectContainer<BaseObject, BaseObject>(statename, identifier, setfunctor, getfunctor, false, true); 455 identifier->addXMLPortObjectContainer(statename, container); 456 } 457 container->port(object, *events, mode); 458 } 459 } 341 460 } 342 461 } -
code/trunk/src/libraries/core/BaseObject.h
r5781 r5929 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)->setObject(this); \43 this->functorGetMainState_ = createFunctor(&classname::getfunction)->setObject(this); \44 }45 46 47 39 #include "CorePrereqs.h" 48 40 … … 53 45 #include "OrxonoxClass.h" 54 46 #include "Super.h" 47 #include "SmartPtr.h" 55 48 56 49 namespace orxonox … … 68 61 virtual ~BaseObject(); 69 62 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 63 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); 70 64 71 65 /** @brief Returns if the object was initialized (passed the object registration). @return True was the object is initialized */ … … 110 104 111 105 void setMainState(bool state); 112 bool getMainState() const; 113 114 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. */ 115 117 inline const std::string& getMainStateName() const { return this->mainStateName_; } 116 virtual void changedMainState(); 118 /** @brief This function gets called if the main state name of the object changes. */ 119 virtual void changedMainStateName(); 117 120 118 121 /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */ … … 134 137 inline BaseObject* getCreator() const { return this->creator_; } 135 138 136 inline void setScene(Scene* scene) { this->scene_ = scene; } 137 inline Scene* getScene() const { return this->scene_; } 138 139 inline void setGametype(Gametype* gametype) 139 inline void setScene(const SmartPtr<Scene>& scene, uint32_t sceneID) { this->scene_ = scene; this->sceneID_=sceneID; } 140 inline const SmartPtr<Scene>& getScene() const { return this->scene_; } 141 inline virtual uint32_t getSceneID() const { return this->sceneID_; } 142 143 inline void setGametype(const SmartPtr<Gametype>& gametype) 140 144 { 141 145 if (gametype != this->gametype_) … … 146 150 } 147 151 } 148 inline Gametype*getGametype() const { return this->gametype_; }152 inline const SmartPtr<Gametype>& getGametype() const { return this->gametype_; } 149 153 inline Gametype* getOldGametype() const { return this->oldGametype_; } 150 154 virtual void changedGametype() {} 151 155 152 void fireEvent(); 153 void fireEvent(bool activate); 154 void fireEvent(bool activate, BaseObject* originator); 156 void addEventSource(BaseObject* source, const std::string& state); 157 void removeEventSource(BaseObject* source); 158 BaseObject* getEventSource(unsigned int index, const std::string& state) const; 159 160 void addEventListener(BaseObject* listener); 161 BaseObject* getEventListener(unsigned int index) const; 162 163 void fireEvent(const std::string& name = ""); 164 void fireEvent(bool activate, const std::string& name = ""); 165 void fireEvent(bool activate, BaseObject* originator, const std::string& name = ""); 155 166 void fireEvent(Event& event); 156 167 157 168 virtual void processEvent(Event& event); 158 159 inline void registerEventListener(BaseObject* object, const std::string& sectionname)160 { this->eventListeners_[object] = sectionname; }161 inline void unregisterEventListener(BaseObject* object)162 { this->eventListeners_.erase(object); }163 164 void addEvent(BaseObject* event, const std::string& sectionname);165 void removeEvent(BaseObject* event);166 BaseObject* getEvent(unsigned int index) const;167 168 void addEventContainer(const std::string& sectionname, EventContainer* container);169 EventContainer* getEventContainer(const std::string& sectionname) const;170 169 171 170 /** @brief Sets the indentation of the debug output in the Loader. @param indentation The indentation */ … … 173 172 /** @brief Returns the indentation of the debug output in the Loader. @return The indentation */ 174 173 inline const std::string& getLoaderIndentation() const { return this->loaderIndentation_; } 174 175 static void loadAllEventStates(Element& xmlelement, XMLPort::Mode mode, BaseObject* object, Identifier* identifier); 175 176 176 177 protected: 178 void addEventState(const std::string& name, EventState* container); 179 EventState* getEventState(const std::string& name) const; 180 177 181 std::string name_; //!< The name of the object 178 182 std::string oldName_; //!< The old name of the object … … 180 184 mbool bVisible_; //!< True = the object is visible 181 185 std::string mainStateName_; 182 Functor* functorSetMainState_; 183 Functor* functorGetMainState_; 186 Functor* mainStateFunctor_; 184 187 185 188 private: 189 /** @brief Adds an object which listens to the events of this object. */ 190 inline void registerEventListener(BaseObject* object) 191 { this->eventListeners_.insert(object); } 192 /** @brief Removes an event listener from this object. */ 193 inline void unregisterEventListener(BaseObject* object) 194 { this->eventListeners_.erase(object); } 195 186 196 void setXMLName(const std::string& name); 187 197 Template* getTemplate(unsigned int index) const; 198 void registerEventStates(); 188 199 189 200 bool bInitialized_; //!< True if the object was initialized (passed the object registration) … … 194 205 Namespace* namespace_; 195 206 BaseObject* creator_; 196 Scene* scene_; 197 Gametype* gametype_; 207 SmartPtr<Scene> scene_; 208 uint32_t sceneID_; 209 SmartPtr<Gametype> gametype_; 198 210 Gametype* oldGametype_; 199 211 std::set<Template*> templates_; 200 std::map<BaseObject*, std::string> eventListeners_; 201 std::list<BaseObject*> events_; 202 std::map<std::string, EventContainer*> eventContainers_; 212 213 std::map<BaseObject*, std::string> eventSources_; //!< List of objects which send events to this object, mapped to the state which they affect 214 std::set<BaseObject*> eventListeners_; //!< List of objects which listen to the events of this object 215 std::set<BaseObject*> eventListenersXML_; //!< List of objects which listen to the events of this object through the "eventlisteners" subsection in XML 216 std::map<std::string, EventState*> eventStates_; //!< Maps the name of the event states to their helper objects 217 bool bRegisteredEventStates_; //!< Becomes true after the object registered its event states (with XMLEventPort) 203 218 }; 204 219 … … 206 221 SUPER_FUNCTION(2, BaseObject, changedActivity, false); 207 222 SUPER_FUNCTION(3, BaseObject, changedVisibility, false); 208 SUPER_FUNCTION(4, BaseObject, processEvent, false); 209 SUPER_FUNCTION(6, BaseObject, changedMainState, false); 210 SUPER_FUNCTION(9, BaseObject, changedName, false); 211 SUPER_FUNCTION(10, BaseObject, changedGametype, false); 223 SUPER_FUNCTION(4, BaseObject, XMLEventPort, false); 224 SUPER_FUNCTION(8, BaseObject, changedName, false); 225 SUPER_FUNCTION(9, BaseObject, changedGametype, false); 212 226 } 213 227 -
code/trunk/src/libraries/core/CMakeLists.txt
r5781 r5929 19 19 20 20 SET_SOURCE_FILES(CORE_SRC_FILES 21 Clock.cc22 ConfigFileManager.cc23 21 ConfigValueContainer.cc 24 22 Core.cc … … 33 31 Language.cc 34 32 LuaState.cc 35 MemoryArchive.cc36 33 ObjectListBase.cc 37 34 OrxonoxClass.cc 38 35 Resource.cc 36 ScopedSingletonManager.cc 39 37 WindowEventListener.cc 40 38 41 39 # command 42 ArgumentCompletionFunctions.cc43 40 CommandEvaluation.cc 44 41 CommandExecutor.cc … … 49 46 50 47 # hierarchy 51 Factory.cc52 48 Identifier.cc 53 49 MetaObjectList.cc … … 67 63 Shell.cc 68 64 TclBind.cc 65 66 COMPILATION_BEGIN FilesystemCompilation.cc 67 ArgumentCompletionFunctions.cc 68 ConfigFileManager.cc 69 MemoryArchive.cc 70 PathConfig.cc 71 COMPILATION_END 72 73 # multithreading 74 ThreadPool.cc 75 COMPILATION_BEGIN ThreadCompilation.cc 69 76 TclThreadManager.cc 70 71 # multithreading72 77 Thread.cc 73 ThreadPool.cc 78 COMPILATION_END 74 79 ) 80 75 81 ADD_SUBDIRECTORY(input) 76 82 -
code/trunk/src/libraries/core/ClassFactory.h
r5781 r5929 42 42 43 43 #include "util/Debug.h" 44 #include "Factory.h"45 44 #include "Identifier.h" 46 45 47 46 namespace orxonox 48 47 { 48 // ########################### 49 // ### Factory ### 50 // ########################### 51 //! Base-class of ClassFactory. 52 class _CoreExport Factory 53 { 54 public: 55 virtual ~Factory() {}; 56 virtual BaseObject* fabricate(BaseObject* creator) = 0; 57 }; 58 49 59 // ############################### 50 60 // ### ClassFactory ### … … 52 62 //! The ClassFactory is able to create new objects of a specific class. 53 63 template <class T> 54 class ClassFactory : public BaseFactory64 class ClassFactory : public Factory 55 65 { 56 66 public: 57 static bool create(const std::string& name, bool bLoadable = true); 58 BaseObject* fabricate(BaseObject* creator); 67 /** 68 @brief Constructor: Adds the ClassFactory to the Identifier of the same type. 69 @param name The name of the class 70 @param bLoadable True if the class can be loaded through XML 71 */ 72 ClassFactory(const std::string& name, bool bLoadable = true) 73 { 74 COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl; 75 ClassIdentifier<T>::getIdentifier(name)->addFactory(this); 76 ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable); 77 } 59 78 60 private: 61 ClassFactory() {} // Don't create 62 ClassFactory(const ClassFactory& factory) {} // Don't copy 63 virtual ~ClassFactory() {} // Don't delete 64 65 static T* createNewObject(BaseObject* creator); 79 /** 80 @brief Creates and returns a new object of class T. 81 @return The new object 82 */ 83 inline BaseObject* fabricate(BaseObject* creator) 84 { 85 return static_cast<BaseObject*>(new T(creator)); 86 } 66 87 }; 67 68 /**69 @brief Adds the ClassFactory to the Identifier of the same type and the Identifier to the Factory.70 @param name The name of the class71 @param bLoadable True if the class can be loaded through XML72 @return Always true (this is needed because the compiler only allows assignments before main())73 */74 template <class T>75 bool ClassFactory<T>::create(const std::string& name, bool bLoadable)76 {77 COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl;78 ClassIdentifier<T>::getIdentifier(name)->addFactory(new ClassFactory<T>);79 ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable);80 Factory::add(name, ClassIdentifier<T>::getIdentifier());81 82 return true;83 }84 85 /**86 @brief Creates and returns a new object of class T.87 @return The new object88 */89 template <class T>90 inline BaseObject* ClassFactory<T>::fabricate(BaseObject* creator)91 {92 return ClassFactory<T>::createNewObject(creator);93 }94 95 /**96 @brief Creates and returns a new object of class T; this is a wrapper for the new operator.97 @return The new object98 */99 template <class T>100 inline T* ClassFactory<T>::createNewObject(BaseObject* creator)101 {102 return new T(creator);103 }104 88 } 105 89 -
code/trunk/src/libraries/core/ClassTreeMask.cc
r5781 r5929 488 488 489 489 // Remove the redundant subnode from the current node 490 delete (*it); 490 491 node->subnodes_.erase(it++); 491 492 } -
code/trunk/src/libraries/core/ClassTreeMask.h
r5781 r5929 265 265 266 266 /** @brief Returns true if the ClassTreeMaskObjectIterator points at the given object. @param pointer The pointer of the object */ 267 inline bool operator==(BaseObject* pointer) const { return ( (*this->objectIterator_) == pointer); }267 inline bool operator==(BaseObject* pointer) const { return (this->objectIterator_ && (*this->objectIterator_) == pointer) || (!this->objectIterator_ && pointer == 0); } 268 268 /** @brief Returns true if the ClassTreeMaskObjectIterator doesn't point at the given object. @param pointer The pointer of the object */ 269 inline bool operator!=(BaseObject* pointer) const { return ( (*this->objectIterator_) != pointer); }269 inline bool operator!=(BaseObject* pointer) const { return (this->objectIterator_ && (*this->objectIterator_) != pointer) || (!this->objectIterator_ && pointer != 0); } 270 270 /** @brief Returns true if the ClassTreeMaskObjectIterator hasn't already reached the end. */ 271 271 inline operator bool() const { return (this->objectIterator_); } -
code/trunk/src/libraries/core/CommandExecutor.cc
r5781 r5929 468 468 CommandExecutor::getEvaluation().listOfPossibleIdentifiers_.clear(); 469 469 std::string lowercase = getLowercase(fragment); 470 for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercase IdentifierMapBegin(); it != Identifier::getLowercaseIdentifierMapEnd(); ++it)470 for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseStringIdentifierMapBegin(); it != Identifier::getLowercaseStringIdentifierMapEnd(); ++it) 471 471 if ((*it).second->hasConsoleCommands()) 472 472 if ((*it).first.find(lowercase) == 0 || fragment == "") … … 516 516 { 517 517 std::string lowercase = getLowercase(name); 518 std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercase IdentifierMap().find(lowercase);519 if ((it != Identifier::getLowercase IdentifierMapEnd()) && (*it).second->hasConsoleCommands())518 std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseStringIdentifierMap().find(lowercase); 519 if ((it != Identifier::getLowercaseStringIdentifierMapEnd()) && (*it).second->hasConsoleCommands()) 520 520 return (*it).second; 521 521 -
code/trunk/src/libraries/core/CommandLine.cc
r5738 r5929 31 31 #include <algorithm> 32 32 #include <sstream> 33 #include <boost/filesystem.hpp>34 33 35 34 #include "util/Convert.h" … … 38 37 #include "util/StringUtils.h" 39 38 #include "util/SubString.h" 40 #include " Core.h"39 #include "PathConfig.h" 41 40 42 41 namespace orxonox … … 285 284 } 286 285 286 infoStr << std::endl; 287 287 infoStr << "Usage: orxonox [options]" << std::endl; 288 288 infoStr << "Available options:" << std::endl; … … 348 348 { 349 349 std::string filename = CommandLine::getValue("optionsFile").getString(); 350 boost::filesystem::path filepath(Core::getConfigPath() / filename);351 350 352 351 // look for additional arguments in given file or start.ini as default 353 352 // They will not overwrite the arguments given directly 354 353 std::ifstream file; 355 file.open( filepath.string().c_str());354 file.open((PathConfig::getConfigPathString() + filename).c_str()); 356 355 std::vector<std::string> args; 357 356 if (file) -
code/trunk/src/libraries/core/ConfigFileManager.cc
r5781 r5929 36 36 #include "ConsoleCommand.h" 37 37 #include "ConfigValueContainer.h" 38 #include " Core.h"38 #include "PathConfig.h" 39 39 40 40 namespace orxonox … … 48 48 bool config(const std::string& classname, const std::string& varname, const std::string& value) 49 49 { 50 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercase IdentifierMap().find(getLowercase(classname));51 if (identifier != Identifier::getLowercase IdentifierMapEnd())50 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname)); 51 if (identifier != Identifier::getLowercaseStringIdentifierMapEnd()) 52 52 { 53 53 std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname)); … … 60 60 bool tconfig(const std::string& classname, const std::string& varname, const std::string& value) 61 61 { 62 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercase IdentifierMap().find(getLowercase(classname));63 if (identifier != Identifier::getLowercase IdentifierMapEnd())62 std::map<std::string, Identifier*>::const_iterator identifier = Identifier::getLowercaseStringIdentifierMap().find(getLowercase(classname)); 63 if (identifier != Identifier::getLowercaseStringIdentifierMapEnd()) 64 64 { 65 65 std::map<std::string, ConfigValueContainer*>::const_iterator variable = (*identifier).second->getLowercaseConfigValueMap().find(getLowercase(varname)); … … 222 222 223 223 // Get default file if necessary and available 224 boost::filesystem::path filepath( Core::getConfigPath() / this->filename_);224 boost::filesystem::path filepath(PathConfig::getConfigPath() / this->filename_); 225 225 if (!boost::filesystem::exists(filepath)) 226 226 { 227 227 // Try to get default one from the data folder 228 boost::filesystem::path defaultFilepath( Core::getDataPath() / "defaultConfig" / this->filename_);228 boost::filesystem::path defaultFilepath(PathConfig::getDataPath() / "defaultConfig" / this->filename_); 229 229 if (boost::filesystem::exists(defaultFilepath)) 230 230 { … … 336 336 { 337 337 std::ofstream file; 338 file.open(( Core::getConfigPathString() + filename_).c_str(), std::fstream::out);338 file.open((PathConfig::getConfigPathString() + filename_).c_str(), std::fstream::out); 339 339 file.setf(std::ios::fixed, std::ios::floatfield); 340 340 file.precision(6); … … 376 376 for (std::list<ConfigFileSection*>::iterator it1 = this->sections_.begin(); it1 != this->sections_.end(); ) 377 377 { 378 std::map<std::string, Identifier*>::const_iterator it2 = Identifier::get IdentifierMap().find((*it1)->getName());379 if (it2 != Identifier::get IdentifierMapEnd() && (*it2).second->hasConfigValues())378 std::map<std::string, Identifier*>::const_iterator it2 = Identifier::getStringIdentifierMap().find((*it1)->getName()); 379 if (it2 != Identifier::getStringIdentifierMapEnd() && (*it2).second->hasConfigValues()) 380 380 { 381 381 // The section exists, delete comment … … 455 455 if (this->type_ == ConfigFileType::Settings) 456 456 { 457 for (std::map<std::string, Identifier*>::const_iterator it = Identifier::get IdentifierMapBegin(); it != Identifier::getIdentifierMapEnd(); ++it)457 for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapBegin(); it != Identifier::getStringIdentifierMapEnd(); ++it) 458 458 { 459 459 if (it->second->hasConfigValues()) -
code/trunk/src/libraries/core/Core.cc
r5781 r5929 37 37 38 38 #include <cassert> 39 #include <fstream> 40 #include <cstdlib> 41 #include <cstdio> 42 #include <boost/version.hpp> 43 #include <boost/filesystem.hpp> 39 #include <vector> 44 40 45 41 #ifdef ORXONOX_PLATFORM_WINDOWS … … 50 46 # undef min 51 47 # undef max 52 #elif defined(ORXONOX_PLATFORM_APPLE)53 # include <sys/param.h>54 # include <mach-o/dyld.h>55 #else /* Linux */56 # include <sys/types.h>57 # include <unistd.h>58 48 #endif 59 49 60 #include " SpecialConfig.h"50 #include "util/Clock.h" 61 51 #include "util/Debug.h" 62 52 #include "util/Exception.h" 63 53 #include "util/SignalHandler.h" 64 #include " Clock.h"54 #include "PathConfig.h" 65 55 #include "CommandExecutor.h" 66 56 #include "CommandLine.h" … … 69 59 #include "CoreIncludes.h" 70 60 #include "DynLibManager.h" 71 #include "Factory.h"72 61 #include "GameMode.h" 73 62 #include "GraphicsManager.h" … … 76 65 #include "Language.h" 77 66 #include "LuaState.h" 67 #include "ScopedSingletonManager.h" 78 68 #include "Shell.h" 79 69 #include "TclBind.h" … … 81 71 #include "input/InputManager.h" 82 72 83 // Boost 1.36 has some issues with deprecated functions that have been omitted84 #if (BOOST_VERSION == 103600)85 # define BOOST_LEAF_FUNCTION filename86 #else87 # define BOOST_LEAF_FUNCTION leaf88 #endif89 90 73 namespace orxonox 91 74 { … … 93 76 Core* Core::singletonPtr_s = 0; 94 77 95 SetCommandLineArgument(externalDataPath, "").information("Path to the external data files");96 SetCommandLineOnlyArgument(writingPathSuffix, "").information("Additional subfolder for config and log files");97 78 SetCommandLineArgument(settingsFile, "orxonox.ini").information("THE configuration file"); 98 79 #ifdef ORXONOX_PLATFORM_WINDOWS … … 117 98 RegisterRootObject(CoreConfiguration); 118 99 this->setConfigValues(); 119 120 // External data directory only exists for dev runs121 if (Core::isDevelopmentRun())122 {123 // Possible data path override by the command line124 if (!CommandLine::getArgument("externalDataPath")->hasDefaultValue())125 tsetExternalDataPath(CommandLine::getValue("externalDataPath"));126 }127 100 } 128 101 … … 194 167 } 195 168 196 /**197 @brief198 Temporary sets the external data path199 @param path200 The new data path201 */202 void tsetExternalDataPath(const std::string& path)203 {204 externalDataPath_ = boost::filesystem::path(path);205 }206 207 169 void initializeRandomNumberGenerator() 208 170 { … … 222 184 std::string language_; //!< The language 223 185 bool bInitializeRandomNumberGenerator_; //!< If true, srand(time(0)) is called 224 225 //! Path to the parent directory of the ones above if program was installed with relativ pahts226 boost::filesystem::path rootPath_;227 boost::filesystem::path executablePath_; //!< Path to the executable228 boost::filesystem::path modulePath_; //!< Path to the modules229 boost::filesystem::path dataPath_; //!< Path to the data file folder230 boost::filesystem::path externalDataPath_; //!< Path to the external data file folder231 boost::filesystem::path configPath_; //!< Path to the config file folder232 boost::filesystem::path logPath_; //!< Path to the log file folder233 186 }; 234 187 … … 240 193 , consoleCommandDestroyer_(CommandExecutor::destroyExternalCommands) 241 194 , configuration_(new CoreConfiguration()) // Don't yet create config values! 242 , bDevRun_(false)243 195 , bGraphicsLoaded_(false) 244 196 { 245 197 // Set the hard coded fixed paths 246 this-> setFixedPaths();198 this->pathConfig_.reset(new PathConfig()); 247 199 248 200 // Create a new dynamic library manager … … 250 202 251 203 // Load modules 252 try 253 { 254 // We search for helper files with the following extension 255 std::string moduleextension = specialConfig::moduleExtension; 256 size_t moduleextensionlength = moduleextension.size(); 257 258 // Search in the directory of our executable 259 boost::filesystem::path searchpath = this->configuration_->modulePath_; 260 261 // Add that path to the PATH variable in case a module depends on another one 262 std::string pathVariable = getenv("PATH"); 263 putenv(const_cast<char*>(("PATH=" + pathVariable + ";" + configuration_->modulePath_.string()).c_str())); 264 265 boost::filesystem::directory_iterator file(searchpath); 266 boost::filesystem::directory_iterator end; 267 268 // Iterate through all files 269 while (file != end) 204 const std::vector<std::string>& modulePaths = this->pathConfig_->getModulePaths(); 205 for (std::vector<std::string>::const_iterator it = modulePaths.begin(); it != modulePaths.end(); ++it) 206 { 207 try 270 208 { 271 std::string filename = file->BOOST_LEAF_FUNCTION(); 272 273 // Check if the file ends with the exension in question 274 if (filename.size() > moduleextensionlength) 275 { 276 if (filename.substr(filename.size() - moduleextensionlength) == moduleextension) 277 { 278 // We've found a helper file - now load the library with the same name 279 std::string library = filename.substr(0, filename.size() - moduleextensionlength); 280 boost::filesystem::path librarypath = searchpath / library; 281 282 try 283 { 284 DynLibManager::getInstance().load(librarypath.string()); 285 } 286 catch (...) 287 { 288 COUT(1) << "Couldn't load module \"" << librarypath.string() << "\": " << Exception::handleMessage() << std::endl; 289 } 290 } 291 } 292 293 ++file; 209 this->dynLibManager_->load(*it); 294 210 } 295 }296 catch (...)297 {298 COUT(1) << "An error occurred while loading modules: " << Exception::handleMessage() << std::endl;211 catch (...) 212 { 213 COUT(1) << "Couldn't load module \"" << *it << "\": " << Exception::handleMessage() << std::endl; 214 } 299 215 } 300 216 … … 303 219 304 220 // Set configurable paths like log, config and media 305 this-> setConfigurablePaths();221 this->pathConfig_->setConfigurablePaths(); 306 222 307 223 // create a signal handler (only active for linux) 308 224 // This call is placed as soon as possible, but after the directories are set 309 225 this->signalHandler_.reset(new SignalHandler()); 310 this->signalHandler_->doCatch( configuration_->executablePath_.string(), Core::getLogPathString() + "orxonox_crash.log");226 this->signalHandler_->doCatch(PathConfig::getExecutablePathString(), PathConfig::getLogPathString() + "orxonox_crash.log"); 311 227 312 228 // Set the correct log path. Before this call, /tmp (Unix) or %TEMP% was used 313 OutputHandler::getOutStream().setLogPath( Core::getLogPathString());229 OutputHandler::getOutStream().setLogPath(PathConfig::getLogPathString()); 314 230 315 231 // Parse additional options file now that we know its path … … 334 250 335 251 // creates the class hierarchy for all classes with factories 336 Factory::createClassHierarchy();252 Identifier::createClassHierarchy(); 337 253 338 254 // Do this soon after the ConfigFileManager has been created to open up the … … 344 260 345 261 // initialise Tcl 346 this->tclBind_.reset(new TclBind( Core::getDataPathString()));262 this->tclBind_.reset(new TclBind(PathConfig::getDataPathString())); 347 263 this->tclThreadManager_.reset(new TclThreadManager(tclBind_->getTclInterpreter())); 348 264 349 265 // create a shell 350 266 this->shell_.reset(new Shell()); 267 268 // Create singletons that always exist (in other libraries) 269 this->rootScope_.reset(new Scope<ScopeID::Root>()); 351 270 } 352 271 … … 370 289 inputManager_.reset(new InputManager()); 371 290 372 // load the CEGUI interface291 // Load the CEGUI interface 373 292 guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow(), 374 293 inputManager_->getMousePosition(), graphicsManager_->isFullScreen())); 375 294 295 bGraphicsLoaded_ = true; 296 GameMode::bShowsGraphics_s = true; 297 298 // Load some sort of a debug overlay (only denoted by its name, "debug.oxo") 299 graphicsManager_->loadDebugOverlay(); 300 301 // Create singletons associated with graphics (in other libraries) 302 graphicsScope_.reset(new Scope<ScopeID::Graphics>()); 303 376 304 unloader.Dismiss(); 377 378 bGraphicsLoaded_ = true;379 305 } 380 306 381 307 void Core::unloadGraphics() 382 308 { 383 this->guiManager_.reset();; 384 this->inputManager_.reset();; 309 this->graphicsScope_.reset(); 310 this->guiManager_.reset(); 311 this->inputManager_.reset(); 385 312 this->graphicsManager_.reset(); 386 313 … … 397 324 398 325 bGraphicsLoaded_ = false; 326 GameMode::bShowsGraphics_s = false; 399 327 } 400 328 … … 457 385 } 458 386 459 /*static*/ void Core::tsetExternalDataPath(const std::string& path)460 {461 getInstance().configuration_->tsetExternalDataPath(path);462 }463 464 /*static*/ const boost::filesystem::path& Core::getDataPath()465 {466 return getInstance().configuration_->dataPath_;467 }468 /*static*/ std::string Core::getDataPathString()469 {470 return getInstance().configuration_->dataPath_.string() + '/';471 }472 473 /*static*/ const boost::filesystem::path& Core::getExternalDataPath()474 {475 return getInstance().configuration_->externalDataPath_;476 }477 /*static*/ std::string Core::getExternalDataPathString()478 {479 return getInstance().configuration_->externalDataPath_.string() + '/';480 }481 482 /*static*/ const boost::filesystem::path& Core::getConfigPath()483 {484 return getInstance().configuration_->configPath_;485 }486 /*static*/ std::string Core::getConfigPathString()487 {488 return getInstance().configuration_->configPath_.string() + '/';489 }490 491 /*static*/ const boost::filesystem::path& Core::getLogPath()492 {493 return getInstance().configuration_->logPath_;494 }495 /*static*/ std::string Core::getLogPathString()496 {497 return getInstance().configuration_->logPath_.string() + '/';498 }499 500 /*static*/ const boost::filesystem::path& Core::getRootPath()501 {502 return getInstance().configuration_->rootPath_;503 }504 /*static*/ std::string Core::getRootPathString()505 {506 return getInstance().configuration_->rootPath_.string() + '/';507 }508 509 387 /** 510 388 @note … … 553 431 } 554 432 555 /**556 @brief557 Retrievs the executable path and sets all hard coded fixed path (currently only the module path)558 Also checks for "orxonox_dev_build.keep_me" in the executable diretory.559 If found it means that this is not an installed run, hence we560 don't write the logs and config files to ~/.orxonox561 @throw562 GeneralException563 */564 void Core::setFixedPaths()565 {566 //////////////////////////567 // FIND EXECUTABLE PATH //568 //////////////////////////569 570 #ifdef ORXONOX_PLATFORM_WINDOWS571 // get executable module572 TCHAR buffer[1024];573 if (GetModuleFileName(NULL, buffer, 1024) == 0)574 ThrowException(General, "Could not retrieve executable path.");575 576 #elif defined(ORXONOX_PLATFORM_APPLE)577 char buffer[1024];578 unsigned long path_len = 1023;579 if (_NSGetExecutablePath(buffer, &path_len))580 ThrowException(General, "Could not retrieve executable path.");581 582 #else /* Linux */583 /* written by Nicolai Haehnle <prefect_@gmx.net> */584 585 /* Get our PID and build the name of the link in /proc */586 char linkname[64]; /* /proc/<pid>/exe */587 if (snprintf(linkname, sizeof(linkname), "/proc/%i/exe", getpid()) < 0)588 {589 /* This should only happen on large word systems. I'm not sure590 what the proper response is here.591 Since it really is an assert-like condition, aborting the592 program seems to be in order. */593 assert(false);594 }595 596 /* Now read the symbolic link */597 char buffer[1024];598 int ret;599 ret = readlink(linkname, buffer, 1024);600 /* In case of an error, leave the handling up to the caller */601 if (ret == -1)602 ThrowException(General, "Could not retrieve executable path.");603 604 /* Ensure proper NUL termination */605 buffer[ret] = 0;606 #endif607 608 configuration_->executablePath_ = boost::filesystem::path(buffer);609 #ifndef ORXONOX_PLATFORM_APPLE610 configuration_->executablePath_ = configuration_->executablePath_.branch_path(); // remove executable name611 #endif612 613 /////////////////////614 // SET MODULE PATH //615 /////////////////////616 617 if (boost::filesystem::exists(configuration_->executablePath_ / "orxonox_dev_build.keep_me"))618 {619 COUT(1) << "Running from the build tree." << std::endl;620 Core::bDevRun_ = true;621 configuration_->modulePath_ = specialConfig::moduleDevDirectory;622 }623 else624 {625 626 #ifdef INSTALL_COPYABLE // --> relative paths627 628 // Also set the root path629 boost::filesystem::path relativeExecutablePath(specialConfig::defaultRuntimePath);630 configuration_->rootPath_ = configuration_->executablePath_;631 while (!boost::filesystem::equivalent(configuration_->rootPath_ / relativeExecutablePath, configuration_->executablePath_)632 && !configuration_->rootPath_.empty())633 configuration_->rootPath_ = configuration_->rootPath_.branch_path();634 if (configuration_->rootPath_.empty())635 ThrowException(General, "Could not derive a root directory. Might the binary installation directory contain '..' when taken relative to the installation prefix path?");636 637 // Module path is fixed as well638 configuration_->modulePath_ = configuration_->rootPath_ / specialConfig::defaultModulePath;639 640 #else641 642 // There is no root path, so don't set it at all643 // Module path is fixed as well644 configuration_->modulePath_ = specialConfig::moduleInstallDirectory;645 646 #endif647 }648 }649 650 /**651 @brief652 Sets config, log and media path and creates folders if necessary.653 @throws654 GeneralException655 */656 void Core::setConfigurablePaths()657 {658 if (Core::isDevelopmentRun())659 {660 configuration_->dataPath_ = specialConfig::dataDevDirectory;661 configuration_->externalDataPath_ = specialConfig::externalDataDevDirectory;662 configuration_->configPath_ = specialConfig::configDevDirectory;663 configuration_->logPath_ = specialConfig::logDevDirectory;664 }665 else666 {667 668 #ifdef INSTALL_COPYABLE // --> relative paths669 670 // Using paths relative to the install prefix, complete them671 configuration_->dataPath_ = configuration_->rootPath_ / specialConfig::defaultDataPath;672 configuration_->configPath_ = configuration_->rootPath_ / specialConfig::defaultConfigPath;673 configuration_->logPath_ = configuration_->rootPath_ / specialConfig::defaultLogPath;674 675 #else676 677 configuration_->dataPath_ = specialConfig::dataInstallDirectory;678 679 // Get user directory680 # ifdef ORXONOX_PLATFORM_UNIX /* Apple? */681 char* userDataPathPtr(getenv("HOME"));682 # else683 char* userDataPathPtr(getenv("APPDATA"));684 # endif685 if (userDataPathPtr == NULL)686 ThrowException(General, "Could not retrieve user data path.");687 boost::filesystem::path userDataPath(userDataPathPtr);688 userDataPath /= ".orxonox";689 690 configuration_->configPath_ = userDataPath / specialConfig::defaultConfigPath;691 configuration_->logPath_ = userDataPath / specialConfig::defaultLogPath;692 693 #endif694 695 }696 697 // Option to put all the config and log files in a separate folder698 if (!CommandLine::getArgument("writingPathSuffix")->hasDefaultValue())699 {700 std::string directory(CommandLine::getValue("writingPathSuffix").getString());701 configuration_->configPath_ = configuration_->configPath_ / directory;702 configuration_->logPath_ = configuration_->logPath_ / directory;703 }704 705 // Create directories to avoid problems when opening files in non existent folders.706 std::vector<std::pair<boost::filesystem::path, std::string> > directories;707 directories.push_back(std::make_pair(boost::filesystem::path(configuration_->configPath_), "config"));708 directories.push_back(std::make_pair(boost::filesystem::path(configuration_->logPath_), "log"));709 710 for (std::vector<std::pair<boost::filesystem::path, std::string> >::iterator it = directories.begin();711 it != directories.end(); ++it)712 {713 if (boost::filesystem::exists(it->first) && !boost::filesystem::is_directory(it->first))714 {715 ThrowException(General, std::string("The ") + it->second + " directory has been preoccupied by a file! \716 Please remove " + it->first.string());717 }718 if (boost::filesystem::create_directories(it->first)) // function may not return true at all (bug?)719 {720 COUT(4) << "Created " << it->second << " directory" << std::endl;721 }722 }723 }724 725 433 void Core::preUpdate(const Clock& time) 726 434 { 435 // singletons from other libraries 436 ScopedSingletonManager::update<ScopeID::Root>(time); 727 437 if (this->bGraphicsLoaded_) 728 438 { … … 731 441 // process gui events 732 442 this->guiManager_->update(time); 443 // graphics singletons from other libraries 444 ScopedSingletonManager::update<ScopeID::Graphics>(time); 733 445 } 734 446 // process thread commands -
code/trunk/src/libraries/core/Core.h
r5781 r5929 28 28 */ 29 29 30 /**31 @file32 @brief33 Declaration of the Core class.34 @details35 The Core class is a singleton, only used to configure some variables36 in the core through the config-file.37 */38 39 30 #ifndef _Core_H__ 40 31 #define _Core_H__ … … 45 36 #include <boost/scoped_ptr.hpp> 46 37 #include "util/OutputHandler.h" 38 #include "util/Scope.h" 47 39 #include "util/ScopeGuard.h" 48 40 #include "util/Singleton.h" … … 55 47 @brief 56 48 The Core class is a singleton used to configure the program basics. 57 @details58 The class provides information about the data, config and log path.59 It determines those by the use of platform specific functions.60 49 @remark 61 50 You should only create this singleton once because it destroys the identifiers! … … 85 74 static void resetLanguage(); 86 75 87 static void tsetExternalDataPath(const std::string& path);88 //! Returns the path to the data files as boost::filesystem::path89 static const boost::filesystem::path& getDataPath();90 //! Returns the path to the external data files as boost::filesystem::path91 static const boost::filesystem::path& getExternalDataPath();92 //! Returns the path to the config files as boost::filesystem::path93 static const boost::filesystem::path& getConfigPath();94 //! Returns the path to the log files as boost::filesystem::path95 static const boost::filesystem::path& getLogPath();96 //! Returns the path to the root folder as boost::filesystem::path97 static const boost::filesystem::path& getRootPath();98 //! Returns the path to the data files as std::string99 static std::string getDataPathString();100 //! Returns the path to the external data files as std::string101 static std::string getExternalDataPathString();102 //! Returns the path to the config files as std::string103 static std::string getConfigPathString();104 //! Returns the path to the log files as std::string105 static std::string getLogPathString();106 //! Returns the path to the root folder as std::string107 static std::string getRootPathString();108 109 static bool isDevelopmentRun() { return getInstance().bDevRun_; }110 111 76 private: 112 77 Core(const Core&); //!< Don't use (undefined symbol) … … 118 83 void unloadGraphics(); 119 84 120 void setFixedPaths();121 void setConfigurablePaths();122 85 void setThreadAffinity(int limitToCPU); 123 86 124 87 // Mind the order for the destruction! 88 scoped_ptr<PathConfig> pathConfig_; 125 89 scoped_ptr<DynLibManager> dynLibManager_; 126 90 scoped_ptr<SignalHandler> signalHandler_; … … 137 101 scoped_ptr<InputManager> inputManager_; //!< Interface to OIS 138 102 scoped_ptr<GUIManager> guiManager_; //!< Interface to GUI 103 scoped_ptr<Scope<ScopeID::Root> > rootScope_; 104 scoped_ptr<Scope<ScopeID::Graphics> > graphicsScope_; 139 105 140 bool bDevRun_; //!< True for runs in the build directory (not installed)141 106 bool bGraphicsLoaded_; 142 143 107 static Core* singletonPtr_s; 144 108 }; -
code/trunk/src/libraries/core/CoreIncludes.h
r5781 r5929 29 29 /** 30 30 @file 31 @brief Definition of macros for Identifier and Factory.31 @brief Definition of macros for Identifiers 32 32 33 33 Every class needs the RegisterObject(class) macro in its constructor. If the class is an interface … … 45 45 #include "util/Debug.h" 46 46 #include "Identifier.h" 47 #include " Factory.h"47 #include "SubclassIdentifier.h" 48 48 #include "ClassFactory.h" 49 49 #include "ObjectList.h" … … 76 76 77 77 /** 78 @brief Creates the entry in theFactory.78 @brief Creates the Factory. 79 79 @param ClassName The name of the class 80 80 */ 81 81 #define CreateFactory(ClassName) \ 82 bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName, true)82 Factory* _##ClassName##Factory = new orxonox::ClassFactory<ClassName>(#ClassName, true) 83 83 84 84 /** 85 @brief Creates the entry in theFactory for classes which should not be loaded through XML.85 @brief Creates the Factory for classes which should not be loaded through XML. 86 86 @param ClassName The name of the class 87 87 */ 88 88 #define CreateUnloadableFactory(ClassName) \ 89 bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName, false)89 Factory* _##ClassName##Factory = new orxonox::ClassFactory<ClassName>(#ClassName, false) 90 90 91 91 /** … … 100 100 { 101 101 /** 102 @brief Returns the Identifier with a given name through the factory.102 @brief Returns the Identifier with a given name. 103 103 @param String The name of the class 104 104 */ 105 105 inline Identifier* ClassByString(const std::string& name) 106 106 { 107 return Factory::getIdentifier(name);107 return Identifier::getIdentifierByString(name); 108 108 } 109 109 110 110 /** 111 @brief Returns the Identifier with a given network ID through the factory. 111 @brief Returns the Identifier with a given lowercase name. 112 @param String The lowercase name of the class 113 */ 114 inline Identifier* ClassByLowercaseString(const std::string& name) 115 { 116 return Identifier::getIdentifierByLowercaseString(name); 117 } 118 119 /** 120 @brief Returns the Identifier with a given network ID. 112 121 @param networkID The network ID of the class 113 122 */ 114 123 inline Identifier* ClassByID(uint32_t id) 115 124 { 116 return Factory::getIdentifier(id);125 return Identifier::getIdentifierByID(id); 117 126 } 118 127 } -
code/trunk/src/libraries/core/CorePrereqs.h
r5738 r5929 28 28 29 29 /** 30 @file 31 @brief Contains all the necessary forward declarations for all classes and structs. 30 @file 31 @brief 32 Shared library macros, enums, constants and forward declarations for the core library 32 33 */ 33 34 … … 40 41 // Shared library settings 41 42 //----------------------------------------------------------------------- 43 42 44 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined( CORE_STATIC_BUILD ) 43 45 # ifdef CORE_SHARED_BUILD … … 56 58 #endif 57 59 58 59 //----------------------------------------------------------------------- 60 // Forward declarations 61 //----------------------------------------------------------------------- 60 //----------------------------------------------------------------------- 61 // Constants 62 //----------------------------------------------------------------------- 63 64 namespace orxonox 65 { 66 static const uint32_t OBJECTID_UNKNOWN = static_cast<uint32_t>(-1); 67 } 68 69 //----------------------------------------------------------------------- 70 // Enums 71 //----------------------------------------------------------------------- 72 62 73 namespace orxonox 63 74 { … … 66 77 enum Mode 67 78 { 79 NOP, 68 80 LoadObject, 69 81 SaveObject, … … 82 94 }; 83 95 }; 84 96 } 97 98 //----------------------------------------------------------------------- 99 // Forward declarations 100 //----------------------------------------------------------------------- 101 102 namespace orxonox 103 { 85 104 typedef std::string LanguageEntryLabel; 86 105 87 106 class ArgumentCompleter; 88 107 class ArgumentCompletionListElement; 89 class BaseFactory;90 class BaseMetaObjectListElement;91 108 class BaseObject; 92 109 template <class T> … … 98 115 class ClassTreeMaskNode; 99 116 class ClassTreeMaskObjectIterator; 100 class Clock;101 117 class CommandEvaluation; 102 class CommandExecutor;103 118 class CommandLine; 104 119 class CommandLineArgument; … … 109 124 class ConfigFileManager; 110 125 class ConfigFileSection; 126 struct ConfigFileType; 111 127 class ConfigValueContainer; 112 128 class ConsoleCommand; … … 115 131 class DynLibManager; 116 132 struct Event; 117 class Event Container;133 class EventState; 118 134 class Executor; 119 135 template <class T> … … 125 141 class FunctorMember; 126 142 class FunctorStatic; 143 class Game; 144 class GameState; 145 struct GameStateInfo; 146 struct GameStateTreeNode; 127 147 class GraphicsManager; 128 148 class GUIManager; … … 131 151 template <class T> 132 152 class Iterator; 133 class IteratorBase;134 153 class Language; 135 class LanguageEntry;136 class Loader;137 154 class LuaState; 138 155 class MemoryArchive; … … 152 169 class OgreWindowEventListener; 153 170 class OrxonoxClass; 171 class PathConfig; 154 172 struct ResourceInfo; 155 173 class Shell; 156 174 class ShellListener; 157 175 template <class T> 176 class SmartPtr; 177 template <class T> 158 178 class SubclassIdentifier; 159 179 class TclBind; … … 163 183 class TclThreadManager; 164 184 class Template; 185 class Thread; 186 class ThreadPool; 187 template <class T> 188 class WeakPtr; 165 189 class WindowEventListener; 166 190 class XMLFile; … … 173 197 class XMLPortParamContainer; 174 198 175 // game states 176 class Game; 177 class GameState; 178 struct GameStateInfo; 179 struct GameStateTreeNode; 180 181 // input 199 // Input 182 200 class BaseCommand; 183 201 class BufferedParamCommand; 184 202 class Button; 185 class CalibratorCallback;186 203 class HalfAxis; 187 204 class InputBuffer; … … 192 209 class InputManager; 193 210 class InputState; 211 struct InputStatePriority; 212 class JoyStickQuantityListener; 194 213 class JoyStick; 214 class KeyBinder; 215 class KeyBinderManager; 216 class Keyboard; 217 class KeyDetector; 218 class KeyEvent; 195 219 class Mouse; 196 class Keyboard;197 class KeyBinder;198 class KeyDetector;199 220 class ParamCommand; 200 221 class SimpleCommand; 201 202 203 // multithreading204 class Thread;205 class ThreadPool;206 222 } 207 223 … … 282 298 namespace orxonox 283 299 { 284 using ticpp::Document;285 300 using ticpp::Element; 286 using ticpp::Declaration; 287 using ticpp::StylesheetReference; 288 using ticpp::Text; 289 using ticpp::Comment; 290 using ticpp::Attribute; 291 } 292 301 } 293 302 294 303 #endif /* _CorePrereqs_H__ */ -
code/trunk/src/libraries/core/Event.cc
r5781 r5929 30 30 31 31 #include "BaseObject.h" 32 #include " Executor.h"32 #include "Identifier.h" 33 33 34 34 namespace orxonox 35 35 { 36 EventContainer::~EventContainer() 36 /** 37 @brief Destructor: Deletes the functor of the event state. 38 */ 39 EventState::~EventState() 37 40 { 38 delete this->eventfunction_; 41 if (this->statefunction_) 42 delete this->statefunction_; 39 43 } 40 44 41 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) 42 52 { 43 if (this->b Active_)53 if (this->bProcessingEvent_) 44 54 { 45 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; 46 56 return; 47 57 } 48 58 49 this->b Active_ = true;59 this->bProcessingEvent_ = true; 50 60 51 if (this->eventname_ == event.sectionname_) 61 // check if the originator is an instance of the requested class 62 if (event.originator_->isA(this->subclass_)) 52 63 { 53 if (event.originator_->isA(this->subclass_)) 64 // actualize the activationcounter 65 if (event.activate_) 66 ++this->activeEvents_; 67 else 54 68 { 55 if (event.activate_) 56 ++this->activeEvents_; 57 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) 58 84 { 59 --this->activeEvents_; 60 61 if (this->activeEvents_ < 0) 62 this->activeEvents_ = 0; 85 // one argument: just the eventstate 86 (*this->statefunction_)(this->activeEvents_); 63 87 } 64 65 if (this->eventfunction_->getParamCount() == 0 && event.activate_) 66 (*this->eventfunction_)(); 67 else if ((this->activeEvents_ == 1 && event.activate_) || (this->activeEvents_ == 0 && !event.activate_)) 88 else if (this->statefunction_->getParamCount() >= 2) 68 89 { 69 if (this->eventfunction_->getParamCount() == 1) 70 (*this->eventfunction_)(this->activeEvents_); 71 else if (this->eventfunction_->getParamCount() >= 2 && event.castedOriginator_) 72 (*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 } 73 102 } 74 103 } 75 104 } 76 105 77 this->b Active_ = false;106 this->bProcessingEvent_ = false; 78 107 } 79 108 } -
code/trunk/src/libraries/core/Event.h
r5781 r5929 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, const std::string& name) : activate_(activate), originator_(originator), name_(name) {} 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 47 std::string name_; //!< The name of this event 45 48 }; 46 49 47 class _CoreExport EventContainer 50 /** 51 @brief The EventState contains information about an event state. 52 53 An event state is a state of an object, which can be changed by events. 54 Event states are changed through functions. Possible functions headers for set event states are: 55 - memoryless state: function() 56 - boolean state: function(bool state) 57 - individual state: function(bool state, SomeClass originator) 58 59 Note that SomeClass may be any class deriving from BaseObject. You will not receive events from originators of other classes. 60 The actual class for SomeClass must be specified as the second argument of the XMLPortEventState macro. 61 62 The this pointer of the affected object is hidden in the functors, because the events are processed in the BaseObject, but some 63 statefunctions may be from child-classes. 64 */ 65 class _CoreExport EventState 48 66 { 49 67 public: 50 Event Container(const std::string& eventname, Executor* eventfunction, Identifier* subclass) : bActive_(false), eventname_(eventname), eventfunction_(eventfunction), subclass_(subclass), activeEvents_(0) {}51 virtual ~Event Container();68 EventState(Functor* statefunction, Identifier* subclass) : bProcessingEvent_(false), activeEvents_(0), statefunction_(statefunction), subclass_(subclass) {} 69 virtual ~EventState(); 52 70 53 void process(BaseObject* object, const Event& event); 71 void process(const Event& event, BaseObject* object); 72 73 Functor* getFunctor() const 74 { return this->statefunction_; } 54 75 55 76 private: 56 bool bActive_; 57 std::string eventname_; 58 Executor* eventfunction_; 59 Identifier* subclass_; 60 61 int activeEvents_; 77 bool bProcessingEvent_; //!< This becomes true while the container processes an event (used to prevent loops) 78 int activeEvents_; //!< The number of events which affect this state and are currently active 79 Functor* statefunction_; //!< A functor to set the state 80 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 81 }; 63 82 } -
code/trunk/src/libraries/core/EventIncludes.h
r5781 r5929 32 32 #include "CorePrereqs.h" 33 33 #include "Executor.h" 34 #include "XMLPort.h" 34 35 35 #define ORXONOX_SET_EVENT(classname, eventname, functionname, event) \ 36 ORXONOX_SET_EVENT_GENERIC(eventcontainer##classname##functionname, classname, eventname, functionname, event, BaseObject) 36 /** 37 @brief Defines a new event state (a state of the object which can be changed by events). 38 39 @param classname The name of this class 40 @param subclassname Usually BaseObject - if different, only instances of this class can send events to this object 41 @param statename The name (string) of this state 42 @param function The function which should be used to set the state 43 @param xmlelement Argument for XMLPort 44 @param mode Argument for XMLPort 45 */ 46 #define XMLPortEventState(classname, subclassname, statename, function, xmlelement, mode) \ 47 orxonox::EventState* containername##function = this->getEventState(statename); \ 48 if (!containername##function) \ 49 { \ 50 containername##function = new orxonox::EventState(orxonox::createFunctor(&classname::function, this), orxonox::ClassIdentifier<subclassname>::getIdentifier()); \ 51 this->addEventState(statename, containername##function); \ 52 } \ 53 XMLPortEventStateIntern(xmlportevent##function, classname, statename, xmlelement, mode) 37 54 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__) 55 /** 56 @brief Like XMLPortEventState but with additional template arguments to identify the function of the state (if ambiguous). 57 */ 58 #define XMLPortEventStateTemplate(classname, subclassname, statename, function, xmlelement, mode, ...) \ 59 orxonox::EventState* containername##function = this->getEventState(statename); \ 60 if (!containername##function) \ 61 { \ 62 containername##function = new orxonox::EventState(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::function, this), orxonox::ClassIdentifier<subclassname>::getIdentifier()); \ 63 this->addEventState(statename, containername##function); \ 64 } \ 65 XMLPortEventStateIntern(xmlportevent##function, classname, statename, xmlelement, mode) 40 66 41 #define ORXONOX_SET_SUBCLASS_EVENT(classname, eventname, functionname, event, subclassname) \ 42 ORXONOX_SET_EVENT_GENERIC(eventcontainer##classname##functionname, classname, eventname, functionname, event, subclassname) 67 #define XMLPortEventStateIntern(name, classname, statename, xmlelement, mode) \ 68 static orxonox::ExecutorMember<classname>* xmlsetfunctor##name = (orxonox::ExecutorMember<classname>*)&orxonox::createExecutor(orxonox::createFunctor(&classname::addEventSource), std::string( #classname ) + "::" + "addEventSource" + "(" + statename + ")")->setDefaultValue(1, statename); \ 69 static orxonox::ExecutorMember<classname>* xmlgetfunctor##name = (orxonox::ExecutorMember<classname>*)&orxonox::createExecutor(orxonox::createFunctor(&classname::getEventSource), std::string( #classname ) + "::" + "getEventSource" + "(" + statename + ")")->setDefaultValue(1, statename); \ 70 XMLPortObjectGeneric(xmlport##name, classname, orxonox::BaseObject, statename, xmlsetfunctor##name, xmlgetfunctor##name, xmlelement, mode, false, true) 71 43 72 44 #define ORXONOX_SET_SUBCLASS_EVENT_TEMPLATE(classname, eventname, functionname, event, subclassname, ...) \ 45 ORXONOX_SET_EVENT_GENERIC_TEMPLATE(eventcontainer##classname##functionname, classname, eventname, functionname, event, subclassname, __VA_ARGS__) 73 /** 74 @brief Defines a new event name for a class. Named events can only have names which were defined with this macro. 75 76 @param classname The name of the class 77 @param name The name of the event 78 */ 79 #define CreateEventName(classname, name) \ 80 static std::string eventname##classname##name = #name 46 81 47 #define ORXONOX_SET_EVENT_GENERIC(containername, classname, eventname, functionname, event, subclassname) \ 48 orxonox::EventContainer* containername = this->getEventContainer(eventname); \ 49 if (!containername) \ 50 { \ 51 ExecutorMember<classname>* executor = orxonox::createExecutor(orxonox::createFunctor(&classname::functionname), std::string( #classname ) + "::" + #functionname); \ 52 executor->setObject(this); \ 53 containername = new orxonox::EventContainer(std::string(eventname), executor, orxonox::ClassIdentifier<subclassname>::getIdentifier()); \ 54 this->addEventContainer(eventname, containername); \ 55 } \ 56 event.castedOriginator_ = orxonox::orxonox_cast<subclassname*>(event.originator_); \ 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 ExecutorMember<classname>* executor = orxonox::createExecutor(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::functionname), std::string( #classname ) + "::" + #functionname); \ 64 executor->setObject(this); \ 65 containername = new orxonox::EventContainer(std::string(eventname), executor, orxonox::ClassIdentifier<subclassname>::getIdentifier()); \ 66 this->addEventContainer(eventname, containername); \ 67 } \ 68 event.castedOriginator_ = orxonox::orxonox_cast<subclassname*>(event.originator_); \ 69 containername->process(this, event) 70 82 /** 83 @brief This macro is needed to fire an event with this name. The event name must previously be declared with @ref CreateEventName. 84 */ 85 #define FireEventName(classname, name) \ 86 eventname##classname##name 87 71 88 #endif /* _EventIncludes_H__ */ -
code/trunk/src/libraries/core/Functor.h
r5738 r5929 191 191 192 192 193 #define FUNCTOR_TEMPLATE(ismember, returnvalue, numparams) FUNCTOR_TEMPLATE##ismember##returnvalue##numparams 194 #define FUNCTOR_TEMPLATE000 195 #define FUNCTOR_TEMPLATE001 template <class P1> 196 #define FUNCTOR_TEMPLATE002 template <class P1, class P2> 197 #define FUNCTOR_TEMPLATE003 template <class P1, class P2, class P3> 198 #define FUNCTOR_TEMPLATE004 template <class P1, class P2, class P3, class P4> 199 #define FUNCTOR_TEMPLATE005 template <class P1, class P2, class P3, class P4, class P5> 200 #define FUNCTOR_TEMPLATE010 template <class R> 201 #define FUNCTOR_TEMPLATE011 template <class R, class P1> 202 #define FUNCTOR_TEMPLATE012 template <class R, class P1, class P2> 203 #define FUNCTOR_TEMPLATE013 template <class R, class P1, class P2, class P3> 204 #define FUNCTOR_TEMPLATE014 template <class R, class P1, class P2, class P3, class P4> 205 #define FUNCTOR_TEMPLATE015 template <class R, class P1, class P2, class P3, class P4, class P5> 206 #define FUNCTOR_TEMPLATE100 template <class T> 207 #define FUNCTOR_TEMPLATE101 template <class T, class P1> 208 #define FUNCTOR_TEMPLATE102 template <class T, class P1, class P2> 209 #define FUNCTOR_TEMPLATE103 template <class T, class P1, class P2, class P3> 210 #define FUNCTOR_TEMPLATE104 template <class T, class P1, class P2, class P3, class P4> 211 #define FUNCTOR_TEMPLATE105 template <class T, class P1, class P2, class P3, class P4, class P5> 212 #define FUNCTOR_TEMPLATE110 template <class T, class R> 213 #define FUNCTOR_TEMPLATE111 template <class T, class R, class P1> 214 #define FUNCTOR_TEMPLATE112 template <class T, class R, class P1, class P2> 215 #define FUNCTOR_TEMPLATE113 template <class T, class R, class P1, class P2, class P3> 216 #define FUNCTOR_TEMPLATE114 template <class T, class R, class P1, class P2, class P3, class P4> 217 #define FUNCTOR_TEMPLATE115 template <class T, class R, class P1, class P2, class P3, class P4, class P5> 193 #define FUNCTOR_TEMPLATE(ismember, returnvalue, numparams, additionalobject) FUNCTOR_TEMPLATE##ismember##returnvalue##numparams(additionalobject) 194 #define FUNCTOR_TEMPLATE000(additionalobject) 195 #define FUNCTOR_TEMPLATE001(additionalobject) template <class P1> 196 #define FUNCTOR_TEMPLATE002(additionalobject) template <class P1, class P2> 197 #define FUNCTOR_TEMPLATE003(additionalobject) template <class P1, class P2, class P3> 198 #define FUNCTOR_TEMPLATE004(additionalobject) template <class P1, class P2, class P3, class P4> 199 #define FUNCTOR_TEMPLATE005(additionalobject) template <class P1, class P2, class P3, class P4, class P5> 200 #define FUNCTOR_TEMPLATE010(additionalobject) template <class R> 201 #define FUNCTOR_TEMPLATE011(additionalobject) template <class R, class P1> 202 #define FUNCTOR_TEMPLATE012(additionalobject) template <class R, class P1, class P2> 203 #define FUNCTOR_TEMPLATE013(additionalobject) template <class R, class P1, class P2, class P3> 204 #define FUNCTOR_TEMPLATE014(additionalobject) template <class R, class P1, class P2, class P3, class P4> 205 #define FUNCTOR_TEMPLATE015(additionalobject) template <class R, class P1, class P2, class P3, class P4, class P5> 206 #define FUNCTOR_TEMPLATE100(additionalobject) template <class T FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) > 207 #define FUNCTOR_TEMPLATE101(additionalobject) template <class T, class P1 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) > 208 #define FUNCTOR_TEMPLATE102(additionalobject) template <class T, class P1, class P2 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) > 209 #define FUNCTOR_TEMPLATE103(additionalobject) template <class T, class P1, class P2, class P3 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) > 210 #define FUNCTOR_TEMPLATE104(additionalobject) template <class T, class P1, class P2, class P3, class P4 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) > 211 #define FUNCTOR_TEMPLATE105(additionalobject) template <class T, class P1, class P2, class P3, class P4, class P5 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) > 212 #define FUNCTOR_TEMPLATE110(additionalobject) template <class T, class R FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) > 213 #define FUNCTOR_TEMPLATE111(additionalobject) template <class T, class R, class P1 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) > 214 #define FUNCTOR_TEMPLATE112(additionalobject) template <class T, class R, class P1, class P2 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) > 215 #define FUNCTOR_TEMPLATE113(additionalobject) template <class T, class R, class P1, class P2, class P3 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) > 216 #define FUNCTOR_TEMPLATE114(additionalobject) template <class T, class R, class P1, class P2, class P3, class P4 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) > 217 #define FUNCTOR_TEMPLATE115(additionalobject) template <class T, class R, class P1, class P2, class P3, class P4, class P5 FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) > 218 219 220 221 #define FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT(additionalobject) FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT##additionalobject 222 #define FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT0 223 #define FUNCTOR_TEMPLATE_ADDITIONAL_OBJECT1 , class O 218 224 219 225 … … 317 323 318 324 #define CREATE_STATIC_FUNCTOR(returnvalue, numparams) \ 319 FUNCTOR_TEMPLATE(0, returnvalue, numparams ) \325 FUNCTOR_TEMPLATE(0, returnvalue, numparams, 0) \ 320 326 class FunctorStatic##returnvalue##numparams : public FunctorStatic \ 321 327 { \ … … 347 353 \ 348 354 \ 349 FUNCTOR_TEMPLATE(0, returnvalue, numparams ) \355 FUNCTOR_TEMPLATE(0, returnvalue, numparams, 0) \ 350 356 inline FunctorStatic##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(0, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \ 351 357 { \ … … 358 364 359 365 #define CREATE_MEMBER_FUNCTOR(returnvalue, numparams) \ 360 FUNCTOR_TEMPLATE(1, returnvalue, numparams ) \366 FUNCTOR_TEMPLATE(1, returnvalue, numparams, 0) \ 361 367 class FunctorMember##returnvalue##numparams : public FunctorMember<T> \ 362 368 { \ … … 391 397 \ 392 398 \ 393 FUNCTOR_TEMPLATE(1, returnvalue, numparams ) \399 FUNCTOR_TEMPLATE(1, returnvalue, numparams, 0) \ 394 400 class FunctorConstMember##returnvalue##numparams : public FunctorMember<T> \ 395 401 { \ … … 423 429 \ 424 430 \ 425 FUNCTOR_TEMPLATE(1, returnvalue, numparams ) \431 FUNCTOR_TEMPLATE(1, returnvalue, numparams, 0) \ 426 432 inline FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams))) \ 427 433 { \ … … 430 436 \ 431 437 \ 432 FUNCTOR_TEMPLATE(1, returnvalue, numparams ) \438 FUNCTOR_TEMPLATE(1, returnvalue, numparams, 0) \ 433 439 inline FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const) \ 434 440 { \ 435 441 return new FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \ 442 } \ 443 \ 444 FUNCTOR_TEMPLATE(1, returnvalue, numparams, 1) \ 445 inline FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)), O* object) \ 446 { \ 447 FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* functor = new FunctorMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \ 448 functor->setObject(object); \ 449 return functor; \ 450 } \ 451 \ 452 \ 453 FUNCTOR_TEMPLATE(1, returnvalue, numparams, 1) \ 454 inline FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* createFunctor(FUNCTOR_FUNCTION_RETURNVALUE(returnvalue) (T::*functionPointer)(FUNCTOR_FUNCTION_PARAMS(numparams)) const, O* object) \ 455 { \ 456 FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams)* functor = new FunctorConstMember##returnvalue##numparams FUNCTOR_TEMPLATE_CLASSES(1, returnvalue, numparams) (functionPointer); \ 457 functor->setObject(object); \ 458 return functor; \ 436 459 } 437 460 -
code/trunk/src/libraries/core/GUIManager.cc
r5781 r5929 49 49 #endif 50 50 51 #include "util/Clock.h" 51 52 #include "util/Debug.h" 52 53 #include "util/Exception.h" 53 54 #include "util/OrxAssert.h" 54 55 #include "Core.h" 55 #include "Clock.h"56 56 #include "LuaState.h" 57 #include "PathConfig.h" 57 58 #include "Resource.h" 58 59 … … 62 63 { 63 64 public: 64 65 void logEvent(const CEGUI::String& message, CEGUI::LoggingLevel level = CEGUI::Standard) 65 66 { 66 67 int orxonoxLevel = CEGUI::Standard; … … 100 101 : renderWindow_(renderWindow) 101 102 , resourceProvider_(0) 103 , camera_(NULL) 102 104 { 103 105 using namespace CEGUI; … … 116 118 // Create our own logger to specify the filepath 117 119 std::auto_ptr<CEGUILogger> ceguiLogger(new CEGUILogger()); 118 ceguiLogger->setLogFilename( Core::getLogPathString() + "cegui.log");120 ceguiLogger->setLogFilename(PathConfig::getLogPathString() + "cegui.log"); 119 121 // set the log level according to ours (translate by subtracting 1) 120 122 ceguiLogger->setLoggingLevel( … … 173 175 void GUIManager::setCamera(Ogre::Camera* camera) 174 176 { 177 this->camera_ = camera; 175 178 if (camera == NULL) 176 179 this->guiRenderer_->setTargetSceneManager(0); -
code/trunk/src/libraries/core/GUIManager.h
r5781 r5929 71 71 72 72 void setCamera(Ogre::Camera* camera); 73 Ogre::Camera* getCamera() { return this->camera_; } 73 74 74 75 static GUIManager* getInstancePtr() { return singletonPtr_s; } … … 101 102 CEGUI::Logger* ceguiLogger_; //!< CEGUI's logger to be able to log CEGUI errors in our log 102 103 std::map<std::string, PlayerInfo*> players_; //!< Stores the player (owner) for each gui 104 Ogre::Camera* camera_; //!< Camera used to render the scene with the GUI 103 105 104 106 static GUIManager* singletonPtr_s; //!< Singleton reference to GUIManager -
code/trunk/src/libraries/core/Game.cc
r5781 r5929 38 38 #include <boost/weak_ptr.hpp> 39 39 40 #include "util/Clock.h" 40 41 #include "util/Debug.h" 41 42 #include "util/Exception.h" … … 43 44 #include "util/Sleep.h" 44 45 #include "util/SubString.h" 45 #include "Clock.h"46 46 #include "CommandLine.h" 47 47 #include "ConsoleCommand.h" … … 57 57 { Game::getInstance().stop(); } 58 58 SetConsoleCommandShortcutExternAlias(stop_game, "exit"); 59 static void printFPS() 60 { COUT(0) << Game::getInstance().getAvgFPS() << std::endl; } 61 SetConsoleCommandShortcutExternAlias(printFPS, "printFPS"); 62 static void printTickTime() 63 { COUT(0) << Game::getInstance().getAvgTickTime() << std::endl; } 64 SetConsoleCommandShortcutExternAlias(printTickTime, "printTickTime"); 59 65 60 66 std::map<std::string, GameStateInfo> Game::gameStateDeclarations_s; … … 111 117 Game::Game(const std::string& cmdLine) 112 118 // Destroy factories before the Core! 113 : gsFactoryDestroyer_(Game::GameStateFactory:: factories_s, &std::map<std::string, shared_ptr<GameStateFactory> >::clear)119 : gsFactoryDestroyer_(Game::GameStateFactory::getFactories(), &std::map<std::string, shared_ptr<GameStateFactory> >::clear) 114 120 { 115 121 this->bAbort_ = false; … … 410 416 requestedNodes.push_back(currentNode); 411 417 } 418 if (currentNode == NULL) 419 requestedNodes.clear(); 412 420 } 413 421 … … 457 465 { 458 466 // Split string into pieces of the form whitespacesText 459 std::vector<std::pair<std::string, unsigned> > stateStrings;467 std::vector<std::pair<std::string, int> > stateStrings; 460 468 size_t pos = 0; 461 469 size_t startPos = 0; 462 470 while (pos < str.size()) 463 471 { 464 unsignedindentation = 0;472 int indentation = 0; 465 473 while(pos < str.size() && str[pos] == ' ') 466 474 ++indentation, ++pos; … … 470 478 stateStrings.push_back(std::make_pair(str.substr(startPos, pos - startPos), indentation)); 471 479 } 472 unsigned int currentLevel = 0; 473 shared_ptr<GameStateTreeNode> currentNode = this->rootStateNode_; 474 for (std::vector<std::pair<std::string, unsigned> >::const_iterator it = stateStrings.begin(); it != stateStrings.end(); ++it) 475 { 476 std::string newStateName = it->first; 477 unsigned newLevel = it->second + 1; // empty root is 0 478 if (!this->checkState(newStateName)) 479 ThrowException(GameState, "GameState with name '" << newStateName << "' not found!"); 480 if (newStateName == this->rootStateNode_->name_) 480 if (stateStrings.empty()) 481 ThrowException(GameState, "Emtpy GameState hierarchy provided, terminating."); 482 // Add element with large identation to detect the last with just an iterator 483 stateStrings.push_back(std::make_pair("", -1)); 484 485 // Parse elements recursively 486 std::vector<std::pair<std::string, int> >::const_iterator begin = stateStrings.begin(); 487 parseStates(begin, this->rootStateNode_); 488 } 489 490 /*** Internal ***/ 491 492 void Game::parseStates(std::vector<std::pair<std::string, int> >::const_iterator& it, shared_ptr<GameStateTreeNode> currentNode) 493 { 494 SubString tokens(it->first, ","); 495 std::vector<std::pair<std::string, int> >::const_iterator startIt = it; 496 497 for (unsigned int i = 0; i < tokens.size(); ++i) 498 { 499 it = startIt; // Reset iterator to the beginning of the sub tree 500 if (!this->checkState(tokens[i])) 501 ThrowException(GameState, "GameState with name '" << tokens[i] << "' not found!"); 502 if (tokens[i] == this->rootStateNode_->name_) 481 503 ThrowException(GameState, "You shouldn't use 'emptyRootGameState' in the hierarchy..."); 482 shared_ptr<GameStateTreeNode> newNode(new GameStateTreeNode); 483 newNode->name_ = newStateName; 484 485 if (newLevel <= currentLevel) 486 { 487 do 488 currentNode = currentNode->parent_.lock(); 489 while (newLevel <= --currentLevel); 490 } 491 if (newLevel == currentLevel + 1) 492 { 493 // Add the child 494 newNode->parent_ = currentNode; 495 currentNode->children_.push_back(newNode); 496 } 497 else 498 ThrowException(GameState, "Indentation error while parsing the hierarchy."); 499 currentNode = newNode; 500 currentLevel = newLevel; 501 } 502 } 503 504 /*** Internal ***/ 504 shared_ptr<GameStateTreeNode> node(new GameStateTreeNode()); 505 node->name_ = tokens[i]; 506 node->parent_ = currentNode; 507 currentNode->children_.push_back(node); 508 509 int currentLevel = it->second; 510 ++it; 511 while (it->second != -1) 512 { 513 if (it->second <= currentLevel) 514 break; 515 else if (it->second == currentLevel + 1) 516 parseStates(it, node); 517 else 518 ThrowException(GameState, "Indentation error while parsing the hierarchy."); 519 } 520 } 521 } 505 522 506 523 void Game::loadGraphics() 507 524 { 508 if (!GameMode:: bShowsGraphics_s)525 if (!GameMode::showsGraphics()) 509 526 { 510 527 core_->loadGraphics(); 511 528 Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics); 512 GameMode::bShowsGraphics_s = true;513 529 514 530 // Construct all the GameStates that require graphics … … 531 547 void Game::unloadGraphics() 532 548 { 533 if (GameMode:: bShowsGraphics_s)549 if (GameMode::showsGraphics()) 534 550 { 535 551 // Destroy all the GameStates that require graphics … … 543 559 544 560 core_->unloadGraphics(); 545 GameMode::bShowsGraphics_s = false;546 561 } 547 562 } … … 607 622 } 608 623 609 std::map<std::string, shared_ptr<Game::GameStateFactory> > Game::GameStateFactory::factories_s; 624 /*static*/ std::map<std::string, shared_ptr<Game::GameStateFactory> >& Game::GameStateFactory::getFactories() 625 { 626 static std::map<std::string, shared_ptr<GameStateFactory> > factories; 627 return factories; 628 } 610 629 611 630 /*static*/ shared_ptr<GameState> Game::GameStateFactory::fabricate(const GameStateInfo& info) 612 631 { 613 std::map<std::string, shared_ptr<Game::GameStateFactory> >::const_iterator it = factories_s.find(info.className);614 assert(it != factories_s.end());632 std::map<std::string, shared_ptr<Game::GameStateFactory> >::const_iterator it = getFactories().find(info.className); 633 assert(it != getFactories().end()); 615 634 return it->second->fabricateInternal(info); 616 635 } -
code/trunk/src/libraries/core/Game.h
r5747 r5929 117 117 template <class T> 118 118 static void createFactory(const std::string& className) 119 { factories_s[className].reset(new TemplateGameStateFactory<T>()); }119 { getFactories()[className].reset(new TemplateGameStateFactory<T>()); } 120 120 121 121 virtual shared_ptr<GameState> fabricateInternal(const GameStateInfo& info) = 0; 122 static std::map<std::string, shared_ptr<GameStateFactory> > factories_s;122 static std::map<std::string, shared_ptr<GameStateFactory> >& getFactories(); 123 123 }; 124 124 template <class T> … … 143 143 void unloadGraphics(); 144 144 145 void parseStates(std::vector<std::pair<std::string, int> >::const_iterator& it, shared_ptr<GameStateTreeNode> currentNode); 145 146 bool checkState(const std::string& name) const; 146 147 void loadState(const std::string& name); -
code/trunk/src/libraries/core/GameMode.cc
r5781 r5929 27 27 */ 28 28 29 /**30 @file31 @brief Implementation of the GameMode class.32 */33 34 29 #include "GameMode.h" 35 30 … … 37 32 { 38 33 bool GameMode::bShowsGraphics_s = false; 34 bool GameMode::bPlaysSound_s = false; 39 35 bool GameMode::bHasServer_s = false; 40 36 bool GameMode::bIsClient_s = false; -
code/trunk/src/libraries/core/GameMode.h
r5781 r5929 41 41 class _CoreExport GameMode 42 42 { 43 friend class Game;43 friend class Core; 44 44 45 45 public: 46 46 static bool showsGraphics() { return bShowsGraphics_s; } 47 static bool playsSound() { return bPlaysSound_s; } 47 48 static bool hasServer() { return bHasServer_s; } 48 49 static bool isClient() { return bIsClient_s; } … … 50 51 static bool isMaster() { return bIsMaster_s; } 51 52 53 static void setPlaysSound (bool val) { bPlaysSound_s = val; } 52 54 static void setHasServer (bool val) { bHasServer_s = val; updateIsMaster(); } 53 55 static void setIsClient (bool val) { bIsClient_s = val; updateIsMaster(); } … … 65 67 66 68 static bool bShowsGraphics_s; //!< global variable that tells whether to show graphics 69 static bool bPlaysSound_s; //!< global variable that tells whether to sound works 67 70 static bool bHasServer_s; //!< global variable that tells whether this is a server 68 71 static bool bIsClient_s; -
code/trunk/src/libraries/core/GameState.h
r5738 r5929 40 40 #include <map> 41 41 #include <string> 42 #include "util/UtilPrereqs.h" 42 43 43 44 namespace orxonox -
code/trunk/src/libraries/core/GraphicsManager.cc
r5781 r5929 48 48 49 49 #include "SpecialConfig.h" 50 #include "util/Clock.h" 50 51 #include "util/Exception.h" 51 52 #include "util/StringUtils.h" 52 53 #include "util/SubString.h" 53 #include "Clock.h"54 54 #include "ConsoleCommand.h" 55 55 #include "ConfigValueIncludes.h" 56 56 #include "CoreIncludes.h" 57 #include "Core.h"58 57 #include "Game.h" 59 58 #include "GameMode.h" 60 59 #include "Loader.h" 61 60 #include "MemoryArchive.h" 61 #include "PathConfig.h" 62 62 #include "WindowEventListener.h" 63 63 #include "XMLFile.h" … … 102 102 103 103 // At first, add the root paths of the data directories as resource locations 104 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( Core::getDataPathString(), "FileSystem", "dataRoot", false);104 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(PathConfig::getDataPathString(), "FileSystem", "dataRoot", false); 105 105 // Load resources 106 106 resources_.reset(new XMLFile("resources.oxr", "dataRoot")); … … 109 109 110 110 // Only for development runs 111 if ( Core::isDevelopmentRun())112 { 113 Ogre::ResourceGroupManager::getSingleton().addResourceLocation( Core::getExternalDataPathString(), "FileSystem", "externalDataRoot", false);111 if (PathConfig::isDevelopmentRun()) 112 { 113 Ogre::ResourceGroupManager::getSingleton().addResourceLocation(PathConfig::getExternalDataPathString(), "FileSystem", "externalDataRoot", false); 114 114 extResources_.reset(new XMLFile("resources.oxr", "externalDataRoot")); 115 115 extResources_->setLuaSupport(false); … … 130 130 GraphicsManager::~GraphicsManager() 131 131 { 132 Loader::unload(debugOverlay_.get()); 133 132 134 Ogre::WindowEventUtilities::removeWindowEventListener(renderWindow_, ogreWindowEventListener_.get()); 133 135 // TODO: Destroy the console command 136 137 // Undeclare the resources 138 Loader::unload(resources_.get()); 139 if (PathConfig::isDevelopmentRun()) 140 Loader::unload(extResources_.get()); 134 141 } 135 142 … … 241 248 } 242 249 243 boost::filesystem::path ogreConfigFilepath( Core::getConfigPath() / this->ogreConfigFile_);244 boost::filesystem::path ogreLogFilepath( Core::getLogPath() / this->ogreLogFile_);250 boost::filesystem::path ogreConfigFilepath(PathConfig::getConfigPath() / this->ogreConfigFile_); 251 boost::filesystem::path ogreLogFilepath(PathConfig::getLogPath() / this->ogreLogFile_); 245 252 246 253 // create a new logManager … … 313 320 314 321 // add console commands 315 FunctorMember<GraphicsManager>* functor1 = createFunctor(&GraphicsManager::printScreen); 316 ccPrintScreen_ = createConsoleCommand(functor1->setObject(this), "printScreen"); 322 ccPrintScreen_ = createConsoleCommand(createFunctor(&GraphicsManager::printScreen, this), "printScreen"); 317 323 CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_); 318 324 } 319 325 326 void GraphicsManager::loadDebugOverlay() 327 { 328 // Load debug overlay to show info about fps and tick time 329 COUT(4) << "Loading Debug Overlay..." << std::endl; 330 debugOverlay_.reset(new XMLFile("debug.oxo")); 331 Loader::open(debugOverlay_.get()); 332 } 333 334 /** 335 @note 336 A note about the Ogre::FrameListener: Even though we don't use them, 337 they still get called. However, the delta times are not correct (except 338 for timeSinceLastFrame, which is the most important). A little research 339 as shown that there is probably only one FrameListener that doesn't even 340 need the time. So we shouldn't run into problems. 341 */ 320 342 void GraphicsManager::update(const Clock& time) 321 343 { … … 418 440 assert(this->renderWindow_); 419 441 420 this->renderWindow_->writeContentsToTimestampedFile( Core::getLogPathString() + "screenShot_", ".jpg");442 this->renderWindow_->writeContentsToTimestampedFile(PathConfig::getLogPathString() + "screenShot_", ".jpg"); 421 443 } 422 444 } -
code/trunk/src/libraries/core/GraphicsManager.h
r5781 r5929 71 71 72 72 void upgradeToGraphics(); 73 void loadDebugOverlay(); 73 74 bool rendererLoaded() const { return renderWindow_ != NULL; } 74 75 … … 99 100 Ogre::Viewport* viewport_; //!< default full size viewport 100 101 101 // XML files for the resources 102 // XML files for the resources and the debug overlay 102 103 shared_ptr<XMLFile> resources_; //!< XML with resource locations 103 104 shared_ptr<XMLFile> extResources_; //!< XML with resource locations in the external path (only for dev runs) 105 shared_ptr<XMLFile> debugOverlay_; //!< XML with various debug overlays 104 106 105 107 // config values -
code/trunk/src/libraries/core/Identifier.cc
r5781 r5929 39 39 #include "ConfigValueContainer.h" 40 40 #include "ConsoleCommand.h" 41 #include " Factory.h"41 #include "ClassFactory.h" 42 42 #include "XMLPort.h" 43 43 … … 61 61 this->bSetName_ = false; 62 62 this->factory_ = 0; 63 this->bLoadable_ = true;63 this->bLoadable_ = false; 64 64 65 65 this->bHasConfigValues_ = false; 66 66 this->bHasConsoleCommands_ = false; 67 67 68 this->children_ = new std::set<const Identifier*>();69 this->directChildren_ = new std::set<const Identifier*>();70 71 68 // Default network ID is the class ID 72 69 this->networkID_ = this->classID_; … … 78 75 Identifier::~Identifier() 79 76 { 80 delete this->children_;81 delete this->directChildren_;82 77 delete this->objects_; 83 78 … … 118 113 // There is already an entry: return it and delete the proposal 119 114 delete proposal; 120 return (*it).second;115 return it->second; 121 116 } 122 117 else … … 165 160 { 166 161 // Tell the parent we're one of it's children 167 (*it)-> getChildrenIntern().insert((*it)->getChildrenIntern().end(), this);162 (*it)->children_.insert((*it)->children_.end(), this); 168 163 169 164 // Erase all parents of our parent from our direct-parent-list … … 187 182 { 188 183 // Tell the parent we're one of it's direct children 189 (*it)-> getDirectChildrenIntern().insert((*it)->getDirectChildrenIntern().end(), this);184 (*it)->directChildren_.insert((*it)->directChildren_.end(), this); 190 185 191 186 // Create the super-function dependencies … … 196 191 197 192 /** 193 @brief Creates the class-hierarchy by creating and destroying one object of each type. 194 */ 195 void Identifier::createClassHierarchy() 196 { 197 COUT(3) << "*** Identifier: Create class-hierarchy" << std::endl; 198 Identifier::startCreatingHierarchy(); 199 for (std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMap().begin(); it != Identifier::getStringIdentifierMap().end(); ++it) 200 { 201 // To create the new branch of the class-hierarchy, we create a new object and delete it afterwards. 202 if (it->second->hasFactory()) 203 { 204 BaseObject* temp = it->second->fabricate(0); 205 temp->destroy(); 206 } 207 } 208 Identifier::stopCreatingHierarchy(); 209 COUT(3) << "*** Identifier: Finished class-hierarchy creation" << std::endl; 210 } 211 212 /** 198 213 @brief Destroys all Identifiers. Called when exiting the program. 199 214 */ … … 214 229 this->name_ = name; 215 230 this->bSetName_ = true; 216 Identifier::getIdentifierMapIntern()[name] = this; 217 Identifier::getLowercaseIdentifierMapIntern()[getLowercase(name)] = this; 231 Identifier::getStringIdentifierMapIntern()[name] = this; 232 Identifier::getLowercaseStringIdentifierMapIntern()[getLowercase(name)] = this; 233 Identifier::getIDIdentifierMapIntern()[this->networkID_] = this; 218 234 } 219 235 } … … 235 251 COUT(1) << "Aborting..." << std::endl; 236 252 abort(); 237 return NULL;238 } 239 } 240 241 /** 242 @brief Sets the network ID to a new value and changes the entry in the Factory.253 return 0; 254 } 255 } 256 257 /** 258 @brief Sets the network ID to a new value and changes the entry in the ID-Identifier-map. 243 259 @param id The new network ID 244 260 */ 245 261 void Identifier::setNetworkID(uint32_t id) 246 262 { 247 Factory::changeNetworkID(this, this->networkID_, id); 263 // Identifier::getIDIdentifierMapIntern().erase(this->networkID_); 264 Identifier::getIDIdentifierMapIntern()[id] = this; 248 265 this->networkID_ = id; 249 266 } … … 291 308 bool Identifier::isParentOf(const Identifier* identifier) const 292 309 { 293 return (this->children_ ->find(identifier) != this->children_->end());310 return (this->children_.find(identifier) != this->children_.end()); 294 311 } 295 312 … … 300 317 bool Identifier::isDirectParentOf(const Identifier* identifier) const 301 318 { 302 return (this->directChildren_ ->find(identifier) != this->directChildren_->end());303 } 304 305 /** 306 @brief Returns the map that stores all Identifiers .319 return (this->directChildren_.find(identifier) != this->directChildren_.end()); 320 } 321 322 /** 323 @brief Returns the map that stores all Identifiers with their names. 307 324 @return The map 308 325 */ 309 std::map<std::string, Identifier*>& Identifier::get IdentifierMapIntern()326 std::map<std::string, Identifier*>& Identifier::getStringIdentifierMapIntern() 310 327 { 311 328 static std::map<std::string, Identifier*> identifierMap; … … 314 331 315 332 /** 316 @brief Returns the map that stores all Identifiers .333 @brief Returns the map that stores all Identifiers with their names in lowercase. 317 334 @return The map 318 335 */ 319 std::map<std::string, Identifier*>& Identifier::getLowercase IdentifierMapIntern()336 std::map<std::string, Identifier*>& Identifier::getLowercaseStringIdentifierMapIntern() 320 337 { 321 338 static std::map<std::string, Identifier*> lowercaseIdentifierMap; 322 339 return lowercaseIdentifierMap; 340 } 341 342 /** 343 @brief Returns the map that stores all Identifiers with their network IDs. 344 @return The map 345 */ 346 std::map<uint32_t, Identifier*>& Identifier::getIDIdentifierMapIntern() 347 { 348 static std::map<uint32_t, Identifier*> identifierMap; 349 return identifierMap; 350 } 351 352 /** 353 @brief Returns the Identifier with a given name. 354 @param name The name of the wanted Identifier 355 @return The Identifier 356 */ 357 Identifier* Identifier::getIdentifierByString(const std::string& name) 358 { 359 std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapIntern().find(name); 360 if (it != Identifier::getStringIdentifierMapIntern().end()) 361 return it->second; 362 else 363 return 0; 364 } 365 366 /** 367 @brief Returns the Identifier with a given name in lowercase. 368 @param name The name of the wanted Identifier 369 @return The Identifier 370 */ 371 Identifier* Identifier::getIdentifierByLowercaseString(const std::string& name) 372 { 373 std::map<std::string, Identifier*>::const_iterator it = Identifier::getLowercaseStringIdentifierMapIntern().find(name); 374 if (it != Identifier::getLowercaseStringIdentifierMapIntern().end()) 375 return it->second; 376 else 377 return 0; 378 } 379 380 /** 381 @brief Returns the Identifier with a given network ID. 382 @param id The network ID of the wanted Identifier 383 @return The Identifier 384 */ 385 Identifier* Identifier::getIdentifierByID(const uint32_t id) 386 { 387 std::map<uint32_t, Identifier*>::const_iterator it = Identifier::getIDIdentifierMapIntern().find(id); 388 if (it != Identifier::getIDIdentifierMapIntern().end()) 389 return it->second; 390 else 391 return 0; 392 } 393 394 /** 395 @brief Cleans the NetworkID map (needed on clients for correct initialization) 396 */ 397 void Identifier::clearNetworkIDs() 398 { 399 Identifier::getIDIdentifierMapIntern().clear(); 323 400 } 324 401 … … 351 428 std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_.find(varname); 352 429 if (it != configValues_.end()) 353 return ((*it).second);430 return it->second; 354 431 else 355 432 return 0; … … 365 442 std::map<std::string, ConfigValueContainer*>::const_iterator it = configValues_LC_.find(varname); 366 443 if (it != configValues_LC_.end()) 367 return ((*it).second);444 return it->second; 368 445 else 369 446 return 0; … … 404 481 std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(name); 405 482 if (it != this->consoleCommands_.end()) 406 return (*it).second;483 return it->second; 407 484 else 408 485 return 0; … … 418 495 std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_LC_.find(name); 419 496 if (it != this->consoleCommands_LC_.end()) 420 return (*it).second;497 return it->second; 421 498 else 422 499 return 0; … … 432 509 std::map<std::string, XMLPortParamContainer*>::const_iterator it = this->xmlportParamContainers_.find(paramname); 433 510 if (it != this->xmlportParamContainers_.end()) 434 return ((*it).second);511 return it->second; 435 512 else 436 513 return 0; … … 463 540 std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportObjectContainers_.find(sectionname); 464 541 if (it != this->xmlportObjectContainers_.end()) 465 return ((*it).second);542 return it->second; 466 543 else 467 544 return 0; … … 483 560 484 561 this->xmlportObjectContainers_[sectionname] = container; 485 }486 487 /**488 @brief Returns a XMLPortEventContainer that attaches an event to this class.489 @param sectionname The name of the section that contains the event490 @return The container491 */492 XMLPortObjectContainer* Identifier::getXMLPortEventContainer(const std::string& eventname)493 {494 std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportEventContainers_.find(eventname);495 if (it != this->xmlportEventContainers_.end())496 return ((*it).second);497 else498 return 0;499 }500 501 /**502 @brief Adds a new XMLPortEventContainer that attaches an event to this class.503 @param sectionname The name of the section that contains the event504 @param container The container505 */506 void Identifier::addXMLPortEventContainer(const std::string& eventname, XMLPortObjectContainer* container)507 {508 std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportEventContainers_.find(eventname);509 if (it != this->xmlportEventContainers_.end())510 {511 COUT(2) << "Warning: Overwriting XMLPortEventContainer in class " << this->getName() << "." << std::endl;512 delete (it->second);513 }514 515 this->xmlportEventContainers_[eventname] = container;516 562 } 517 563 … … 525 571 { 526 572 for (std::set<const Identifier*>::const_iterator it = list.begin(); it != list.end(); ++it) 527 out << (*it)->getName() << " "; 573 { 574 if (it != list.begin()) 575 out << " "; 576 out << (*it)->getName(); 577 } 528 578 529 579 return out; -
code/trunk/src/libraries/core/Identifier.h
r5781 r5929 29 29 /** 30 30 @file 31 @brief Definition of the Identifier , ClassIdentifier and SubclassIdentifier classes, implementation of the ClassIdentifier and SubclassIdentifier classes.31 @brief Definition of the Identifier class, definition and implementation of the ClassIdentifier class. 32 32 33 33 The Identifier contains all needed information about the class it belongs to: … … 45 45 46 46 Every Identifier is in fact a ClassIdentifier, but they are derived from Identifier. 47 48 SubclassIdentifier is a separated class, acting like an Identifier, but has a given class.49 You can only assign Identifiers of exactly the given class or of a derivative to a SubclassIdentifier.50 47 */ 51 48 … … 90 87 class _CoreExport Identifier 91 88 { 92 template <class T>93 friend class SubclassIdentifier;94 95 friend class Factory;96 97 89 public: 90 /** @brief Returns the name of the class the Identifier belongs to. @return The name */ 91 inline const std::string& getName() const { return this->name_; } 92 void setName(const std::string& name); 93 94 /** @brief Returns the network ID to identify a class through the network. @return the network ID */ 95 inline const uint32_t getNetworkID() const { return this->networkID_; } 96 void setNetworkID(uint32_t id); 97 98 /** @brief Returns the unique ID of the class */ 99 FORCEINLINE unsigned int getClassID() const { return this->classID_; } 100 101 /** @brief Returns the list of all existing objects of this class. @return The list */ 102 inline ObjectListBase* getObjects() const { return this->objects_; } 103 98 104 /** @brief Sets the Factory. @param factory The factory to assign */ 99 inline void addFactory(BaseFactory* factory) { this->factory_ = factory; } 105 inline void addFactory(Factory* factory) { this->factory_ = factory; } 106 /** @brief Returns true if the Identifier has a Factory. */ 107 inline bool hasFactory() const { return (this->factory_ != 0); } 100 108 101 109 BaseObject* fabricate(BaseObject* creator); 110 111 /** @brief Returns true if the class can be loaded through XML. */ 112 inline bool isLoadable() const { return this->bLoadable_; } 113 /** @brief Set the class to be loadable through XML or not. */ 114 inline void setLoadable(bool bLoadable) { this->bLoadable_ = bLoadable; } 115 102 116 bool isA(const Identifier* identifier) const; 103 117 bool isExactlyA(const Identifier* identifier) const; … … 107 121 bool isDirectParentOf(const Identifier* identifier) const; 108 122 109 /** @brief Returns true if the class can be loaded through XML. */ 110 inline bool isLoadable() const { return this->bLoadable_; } 111 /** @brief Set the class to be loadable through XML or not. */ 112 inline void setLoadable(bool bLoadable) { this->bLoadable_ = bLoadable; } 113 114 /** @brief Returns the list of all existing objects of this class. @return The list */ 115 inline ObjectListBase* getObjects() const 116 { return this->objects_; } 117 118 /** @brief Returns the name of the class the Identifier belongs to. @return The name */ 119 inline const std::string& getName() const { return this->name_; } 120 void setName(const std::string& name); 121 122 virtual void updateConfigValues(bool updateChildren = true) const = 0; 123 124 ///////////////////////////// 125 ////// Class Hierarchy ////// 126 ///////////////////////////// 127 static void createClassHierarchy(); 128 129 /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */ 130 inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); } 123 131 124 132 /** @brief Returns the parents of the class the Identifier belongs to. @return The list of all parents */ … … 130 138 131 139 /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */ 132 inline const std::set<const Identifier*>& getChildren() const { return (*this->children_); }140 inline const std::set<const Identifier*>& getChildren() const { return this->children_; } 133 141 /** @brief Returns the begin-iterator of the children-list. @return The begin-iterator */ 134 inline std::set<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_ ->begin(); }142 inline std::set<const Identifier*>::const_iterator getChildrenBegin() const { return this->children_.begin(); } 135 143 /** @brief Returns the end-iterator of the children-list. @return The end-iterator */ 136 inline std::set<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_ ->end(); }144 inline std::set<const Identifier*>::const_iterator getChildrenEnd() const { return this->children_.end(); } 137 145 138 146 /** @brief Returns the direct parents of the class the Identifier belongs to. @return The list of all direct parents */ … … 144 152 145 153 /** @brief Returns the direct children the class the Identifier belongs to. @return The list of all direct children */ 146 inline const std::set<const Identifier*>& getDirectChildren() const { return (*this->directChildren_); }154 inline const std::set<const Identifier*>& getDirectChildren() const { return this->directChildren_; } 147 155 /** @brief Returns the begin-iterator of the direct-children-list. @return The begin-iterator */ 148 inline std::set<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_ ->begin(); }156 inline std::set<const Identifier*>::const_iterator getDirectChildrenBegin() const { return this->directChildren_.begin(); } 149 157 /** @brief Returns the end-iterator of the direct-children-list. @return The end-iterator */ 150 inline std::set<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_->end(); } 151 152 153 /** @brief Returns the map that stores all Identifiers. @return The map */ 154 static inline const std::map<std::string, Identifier*>& getIdentifierMap() { return Identifier::getIdentifierMapIntern(); } 155 /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers. @return The const_iterator */ 156 static inline std::map<std::string, Identifier*>::const_iterator getIdentifierMapBegin() { return Identifier::getIdentifierMap().begin(); } 157 /** @brief Returns a const_iterator to the end of the map that stores all Identifiers. @return The const_iterator */ 158 static inline std::map<std::string, Identifier*>::const_iterator getIdentifierMapEnd() { return Identifier::getIdentifierMap().end(); } 158 inline std::set<const Identifier*>::const_iterator getDirectChildrenEnd() const { return this->directChildren_.end(); } 159 160 161 ////////////////////////// 162 ///// Identifier Map ///// 163 ////////////////////////// 164 static void destroyAllIdentifiers(); 165 166 static Identifier* getIdentifierByString(const std::string& name); 167 static Identifier* getIdentifierByLowercaseString(const std::string& name); 168 static Identifier* getIdentifierByID(uint32_t id); 169 170 static void clearNetworkIDs(); 171 172 /** @brief Returns the map that stores all Identifiers with their names. @return The map */ 173 static inline const std::map<std::string, Identifier*>& getStringIdentifierMap() { return Identifier::getStringIdentifierMapIntern(); } 174 /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their names. @return The const_iterator */ 175 static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapBegin() { return Identifier::getStringIdentifierMap().begin(); } 176 /** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their names. @return The const_iterator */ 177 static inline std::map<std::string, Identifier*>::const_iterator getStringIdentifierMapEnd() { return Identifier::getStringIdentifierMap().end(); } 159 178 160 179 /** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */ 161 static inline const std::map<std::string, Identifier*>& getLowercase IdentifierMap() { return Identifier::getLowercaseIdentifierMapIntern(); }180 static inline const std::map<std::string, Identifier*>& getLowercaseStringIdentifierMap() { return Identifier::getLowercaseStringIdentifierMapIntern(); } 162 181 /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */ 163 static inline std::map<std::string, Identifier*>::const_iterator getLowercase IdentifierMapBegin() { return Identifier::getLowercaseIdentifierMap().begin(); }182 static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapBegin() { return Identifier::getLowercaseStringIdentifierMap().begin(); } 164 183 /** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their names in lowercase. @return The const_iterator */ 165 static inline std::map<std::string, Identifier*>::const_iterator getLowercaseIdentifierMapEnd() { return Identifier::getLowercaseIdentifierMap().end(); } 166 184 static inline std::map<std::string, Identifier*>::const_iterator getLowercaseStringIdentifierMapEnd() { return Identifier::getLowercaseStringIdentifierMap().end(); } 185 186 /** @brief Returns the map that stores all Identifiers with their IDs. @return The map */ 187 static inline const std::map<uint32_t, Identifier*>& getIDIdentifierMap() { return Identifier::getIDIdentifierMapIntern(); } 188 /** @brief Returns a const_iterator to the beginning of the map that stores all Identifiers with their IDs. @return The const_iterator */ 189 static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapBegin() { return Identifier::getIDIdentifierMap().begin(); } 190 /** @brief Returns a const_iterator to the end of the map that stores all Identifiers with their IDs. @return The const_iterator */ 191 static inline std::map<uint32_t, Identifier*>::const_iterator getIDIdentifierMapEnd() { return Identifier::getIDIdentifierMap().end(); } 192 193 194 ///////////////////////// 195 ///// Config Values ///// 196 ///////////////////////// 197 virtual void updateConfigValues(bool updateChildren = true) const = 0; 198 199 /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */ 200 inline bool hasConfigValues() const { return this->bHasConfigValues_; } 167 201 168 202 /** @brief Returns the map that stores all config values. @return The const_iterator */ … … 180 214 inline std::map<std::string, ConfigValueContainer*>::const_iterator getLowercaseConfigValueMapEnd() const { return this->configValues_LC_.end(); } 181 215 216 void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container); 217 ConfigValueContainer* getConfigValueContainer(const std::string& varname); 218 ConfigValueContainer* getLowercaseConfigValueContainer(const std::string& varname); 219 220 221 //////////////////////////// 222 ///// Console Commands ///// 223 //////////////////////////// 224 /** @brief Returns true if this class has at least one console command. @return True if this class has at least one console command */ 225 inline bool hasConsoleCommands() const { return this->bHasConsoleCommands_; } 182 226 183 227 /** @brief Returns the map that stores all console commands. @return The const_iterator */ … … 195 239 inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandMapEnd() const { return this->consoleCommands_LC_.end(); } 196 240 241 ConsoleCommand& addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut); 242 ConsoleCommand* getConsoleCommand(const std::string& name) const; 243 ConsoleCommand* getLowercaseConsoleCommand(const std::string& name) const; 244 245 246 /////////////////// 247 ///// XMLPort ///// 248 /////////////////// 197 249 /** @brief Returns the map that stores all XMLPort params. @return The const_iterator */ 198 250 inline const std::map<std::string, XMLPortParamContainer*>& getXMLPortParamMap() const { return this->xmlportParamContainers_; } … … 209 261 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapEnd() const { return this->xmlportObjectContainers_.end(); } 210 262 211 /** @brief Returns the map that stores all XMLPort events. @return The const_iterator */212 inline const std::map<std::string, XMLPortObjectContainer*>& getXMLPortEventMap() const { return this->xmlportEventContainers_; }213 /** @brief Returns a const_iterator to the beginning of the map that stores all XMLPort events. @return The const_iterator */214 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortEventMapBegin() const { return this->xmlportEventContainers_.begin(); }215 /** @brief Returns a const_iterator to the end of the map that stores all XMLPort events. @return The const_iterator */216 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortEventMapEnd() const { return this->xmlportEventContainers_.end(); }217 218 /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */219 inline bool hasConfigValues() const { return this->bHasConfigValues_; }220 /** @brief Returns true if this class has at least one console command. @return True if this class has at least one console command */221 inline bool hasConsoleCommands() const { return this->bHasConsoleCommands_; }222 223 /** @brief Returns true, if a branch of the class-hierarchy is being created, causing all new objects to store their parents. @return The status of the class-hierarchy creation */224 inline static bool isCreatingHierarchy() { return (hierarchyCreatingCounter_s > 0); }225 226 /** @brief Returns the network ID to identify a class through the network. @return the network ID */227 inline const uint32_t getNetworkID() const { return this->networkID_; }228 229 /** @brief Sets the network ID to a new value. @param id The new value */230 void setNetworkID(uint32_t id);231 232 /** @brief Returns the unique ID of the class */233 FORCEINLINE unsigned int getClassID() const { return this->classID_; }234 235 void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container);236 ConfigValueContainer* getConfigValueContainer(const std::string& varname);237 ConfigValueContainer* getLowercaseConfigValueContainer(const std::string& varname);238 239 263 void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container); 240 264 XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname); … … 243 267 XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname); 244 268 245 void addXMLPortEventContainer(const std::string& eventname, XMLPortObjectContainer* container);246 XMLPortObjectContainer* getXMLPortEventContainer(const std::string& eventname);247 248 ConsoleCommand& addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut);249 ConsoleCommand* getConsoleCommand(const std::string& name) const;250 ConsoleCommand* getLowercaseConsoleCommand(const std::string& name) const;251 252 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);253 254 static void destroyAllIdentifiers();255 269 256 270 protected: … … 262 276 virtual void createSuperFunctionCaller() const = 0; 263 277 264 /** @brief Returns the map that stores all Identifiers. @return The map */ 265 static std::map<std::string, Identifier*>& getIdentifierMapIntern(); 278 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass); 279 280 /** @brief Returns the map that stores all Identifiers with their names. @return The map */ 281 static std::map<std::string, Identifier*>& getStringIdentifierMapIntern(); 266 282 /** @brief Returns the map that stores all Identifiers with their names in lowercase. @return The map */ 267 static std::map<std::string, Identifier*>& getLowercaseIdentifierMapIntern(); 283 static std::map<std::string, Identifier*>& getLowercaseStringIdentifierMapIntern(); 284 /** @brief Returns the map that stores all Identifiers with their network IDs. @return The map */ 285 static std::map<uint32_t, Identifier*>& getIDIdentifierMapIntern(); 268 286 269 287 /** @brief Returns the children of the class the Identifier belongs to. @return The list of all children */ 270 inline std::set<const Identifier*>& getChildrenIntern() const { return (*this->children_); }288 inline std::set<const Identifier*>& getChildrenIntern() const { return this->children_; } 271 289 /** @brief Returns the direct children of the class the Identifier belongs to. @return The list of all direct children */ 272 inline std::set<const Identifier*>& getDirectChildrenIntern() const { return (*this->directChildren_); }290 inline std::set<const Identifier*>& getDirectChildrenIntern() const { return this->directChildren_; } 273 291 274 292 ObjectListBase* objects_; //!< The list of all objects of this class 275 293 276 294 private: 277 /** 278 @brief Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents. 279 */ 280 inline static void startCreatingHierarchy() 281 { 282 hierarchyCreatingCounter_s++; 283 COUT(4) << "*** Identifier: Increased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl; 284 } 285 286 /** 287 @brief Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents. 288 */ 289 inline static void stopCreatingHierarchy() 290 { 291 hierarchyCreatingCounter_s--; 292 COUT(4) << "*** Identifier: Decreased Hierarchy-Creating-Counter to " << hierarchyCreatingCounter_s << std::endl; 293 } 295 /** @brief Increases the hierarchyCreatingCounter_s variable, causing all new objects to store their parents. */ 296 inline static void startCreatingHierarchy() { hierarchyCreatingCounter_s++; } 297 /** @brief Decreases the hierarchyCreatingCounter_s variable, causing the objects to stop storing their parents. */ 298 inline static void stopCreatingHierarchy() { hierarchyCreatingCounter_s--; } 294 299 295 300 static std::map<std::string, Identifier*>& getTypeIDIdentifierMap(); … … 298 303 299 304 std::set<const Identifier*> parents_; //!< The parents of the class the Identifier belongs to 300 std::set<const Identifier*>* children_;//!< The children of the class the Identifier belongs to305 mutable std::set<const Identifier*> children_; //!< The children of the class the Identifier belongs to 301 306 302 307 std::set<const Identifier*> directParents_; //!< The direct parents of the class the Identifier belongs to 303 std::set<const Identifier*>* directChildren_;//!< The direct children of the class the Identifier belongs to308 mutable std::set<const Identifier*> directChildren_; //!< The direct children of the class the Identifier belongs to 304 309 305 310 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) … … 307 312 bool bLoadable_; //!< False = it's not permitted to load the object through XML 308 313 std::string name_; //!< The name of the class the Identifier belongs to 309 BaseFactory* factory_;//!< The Factory, able to create new objects of the given class (if available)314 Factory* factory_; //!< The Factory, able to create new objects of the given class (if available) 310 315 static int hierarchyCreatingCounter_s; //!< Bigger than zero if at least one Identifier stores its parents (its an int instead of a bool to avoid conflicts with multithreading) 311 316 uint32_t networkID_; //!< The network ID to identify a class through the network … … 323 328 std::map<std::string, XMLPortParamContainer*> xmlportParamContainers_; //!< All loadable parameters 324 329 std::map<std::string, XMLPortObjectContainer*> xmlportObjectContainers_; //!< All attachable objects 325 std::map<std::string, XMLPortObjectContainer*> xmlportEventContainers_; //!< All events326 330 }; 327 331 … … 348 352 349 353 public: 350 static ClassIdentifier<T> *getIdentifier();351 static ClassIdentifier<T> *getIdentifier(const std::string& name);354 static ClassIdentifier<T>* getIdentifier(); 355 static ClassIdentifier<T>* getIdentifier(const std::string& name); 352 356 353 357 bool initialiseObject(T* object, const std::string& className, bool bRootClass); … … 380 384 inline ClassIdentifier<T>* ClassIdentifier<T>::getIdentifier() 381 385 { 382 // check if the static field has already been filled383 if ( ClassIdentifier<T>::classIdentifier_s == 0)386 // check if the Identifier already exists 387 if (!ClassIdentifier<T>::classIdentifier_s) 384 388 ClassIdentifier<T>::initialiseIdentifier(); 385 389 … … 508 512 #endif 509 513 } 510 511 512 // ###############################513 // ### SubclassIdentifier ###514 // ###############################515 //! The SubclassIdentifier acts almost like an Identifier, but has some prerequisites.516 /**517 You can only assign an Identifier that belongs to a class T (or derived) to a SubclassIdentifier<T>.518 If you assign something else, the program aborts.519 Because we know the minimum type, a dynamic_cast is done, which makes it easier to create a new object.520 */521 template <class T>522 class SubclassIdentifier523 {524 public:525 /**526 @brief Constructor: Automaticaly assigns the Identifier of the given class.527 */528 SubclassIdentifier()529 {530 this->identifier_ = ClassIdentifier<T>::getIdentifier();531 }532 533 /**534 @brief Copyconstructor: Assigns the given Identifier.535 @param identifier The Identifier536 */537 SubclassIdentifier(Identifier* identifier)538 {539 this->operator=(identifier);540 }541 542 /**543 @brief Overloading of the = operator: assigns the identifier and checks its type.544 @param identifier The Identifier to assign545 @return The SubclassIdentifier itself546 */547 SubclassIdentifier<T>& operator=(Identifier* identifier)548 {549 if (!identifier || !identifier->isA(ClassIdentifier<T>::getIdentifier()))550 {551 COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;552 if (identifier)553 {554 COUT(1) << "Error: Class " << identifier->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;555 COUT(1) << "Error: SubclassIdentifier<" << ClassIdentifier<T>::getIdentifier()->getName() << "> = Class(" << identifier->getName() << ") is forbidden." << std::endl;556 }557 else558 {559 COUT(1) << "Error: Can't assign NULL identifier" << std::endl;560 }561 }562 else563 {564 this->identifier_ = identifier;565 }566 return *this;567 }568 569 /**570 @brief Overloading of the * operator: returns the assigned identifier.571 */572 inline Identifier* operator*() const573 {574 return this->identifier_;575 }576 577 /**578 @brief Overloading of the -> operator: returns the assigned identifier.579 */580 inline Identifier* operator->() const581 {582 return this->identifier_;583 }584 585 /**586 @brief Returns the assigned identifier. This allows you to assign a SubclassIdentifier to a normal Identifier*.587 */588 inline operator Identifier*() const589 {590 return this->identifier_;591 }592 593 /**594 @brief Creates a new object of the type of the assigned Identifier and dynamic_casts it to the minimal type given by T.595 @return The new object596 */597 T* fabricate(BaseObject* creator) const598 {599 BaseObject* newObject = this->identifier_->fabricate(creator);600 601 // Check if the creation was successful602 if (newObject)603 {604 return orxonox_cast<T*>(newObject);605 }606 else607 {608 // Something went terribly wrong609 if (this->identifier_)610 {611 COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;612 COUT(1) << "Error: Class " << this->identifier_->getName() << " is not a " << ClassIdentifier<T>::getIdentifier()->getName() << "!" << std::endl;613 COUT(1) << "Error: Couldn't fabricate a new Object." << std::endl;614 COUT(1) << "Aborting..." << std::endl;615 }616 else617 {618 COUT(1) << "An error occurred in SubclassIdentifier (Identifier.h):" << std::endl;619 COUT(1) << "Error: Couldn't fabricate a new Object - Identifier is undefined." << std::endl;620 COUT(1) << "Aborting..." << std::endl;621 }622 623 assert(false);624 return 0;625 }626 }627 628 /** @brief Returns the assigned identifier. @return The identifier */629 inline Identifier* getIdentifier() const630 { return this->identifier_; }631 632 // /** @brief Returns true, if the assigned identifier is at least of the given type. @param identifier The identifier to compare with */633 // inline bool isA(const Identifier* identifier) const634 // { return this->identifier_->isA(identifier); }635 //636 // /** @brief Returns true, if the assigned identifier is exactly of the given type. @param identifier The identifier to compare with */637 // inline bool isExactlyA(const Identifier* identifier) const638 // { return this->identifier_->isExactlyA(identifier); }639 //640 // /** @brief Returns true, if the assigned identifier is a child of the given identifier. @param identifier The identifier to compare with */641 // inline bool isChildOf(const Identifier* identifier) const642 // { return this->identifier_->isChildOf(identifier); }643 //644 // /** @brief Returns true, if the assigned identifier is a direct child of the given identifier. @param identifier The identifier to compare with */645 // inline bool isDirectChildOf(const Identifier* identifier) const646 // { return this->identifier_->isDirectChildOf(identifier); }647 //648 // /** @brief Returns true, if the assigned identifier is a parent of the given identifier. @param identifier The identifier to compare with */649 // inline bool isParentOf(const Identifier* identifier) const650 // { return this->identifier_->isParentOf(identifier); }651 //652 // /** @brief Returns true, if the assigned identifier is a direct parent of the given identifier. @param identifier The identifier to compare with */653 // inline bool isDirectParentOf(const Identifier* identifier) const654 // { return this->identifier_->isDirectParentOf(identifier); }655 656 private:657 Identifier* identifier_; //!< The assigned identifier658 };659 514 } 660 515 -
code/trunk/src/libraries/core/Iterator.h
r5738 r5929 167 167 168 168 return (*this); 169 return *this;170 169 } 171 170 … … 193 192 inline const Iterator<T>& operator++() 194 193 { 195 if (this->element_) 196 this->element_ = this->element_->next_; 194 this->element_ = this->element_->next_; 197 195 return *this; 198 196 } … … 205 203 { 206 204 Iterator<T> copy = *this; 207 if (this->element_) 208 this->element_ = this->element_->next_; 205 this->element_ = this->element_->next_; 209 206 return copy; 210 207 } … … 216 213 inline const Iterator<T>& operator--() 217 214 { 218 if (this->element_) 219 this->element_ = this->element_->prev_; 215 this->element_ = this->element_->prev_; 220 216 return *this; 221 217 } … … 228 224 { 229 225 Iterator<T> copy = *this; 230 if (this->element_) 231 this->element_ = this->element_->prev_; 226 this->element_ = this->element_->prev_; 232 227 return copy; 233 228 } … … 239 234 inline T* operator*() const 240 235 { 241 if (this->element_) 242 return orxonox_cast<T*>(this->element_->objectBase_); 243 else 244 return 0; 236 return orxonox_cast<T*>(this->element_->objectBase_); 245 237 } 246 238 … … 251 243 inline T* operator->() const 252 244 { 253 if (this->element_) 254 return orxonox_cast<T*>(this->element_->objectBase_); 255 else 256 return 0; 245 return orxonox_cast<T*>(this->element_->objectBase_); 257 246 } 258 247 -
code/trunk/src/libraries/core/Language.cc
r5738 r5929 35 35 36 36 #include <fstream> 37 #include <boost/filesystem.hpp>38 39 37 #include "util/Debug.h" 40 38 #include "Core.h" 39 #include "PathConfig.h" 41 40 42 41 namespace orxonox … … 200 199 COUT(4) << "Read default language file." << std::endl; 201 200 202 boost::filesystem::path filepath(Core::getConfigPath() / getFilename(this->defaultLanguage_));201 std::string filepath = PathConfig::getConfigPathString() + getFilename(this->defaultLanguage_); 203 202 204 203 // This creates the file if it's not existing 205 204 std::ofstream createFile; 206 createFile.open(filepath. string().c_str(), std::fstream::app);205 createFile.open(filepath.c_str(), std::fstream::app); 207 206 createFile.close(); 208 207 209 208 // Open the file 210 209 std::ifstream file; 211 file.open(filepath. string().c_str(), std::fstream::in);210 file.open(filepath.c_str(), std::fstream::in); 212 211 213 212 if (!file.is_open()) … … 249 248 COUT(4) << "Read translated language file (" << Core::getLanguage() << ")." << std::endl; 250 249 251 boost::filesystem::path filepath(Core::getConfigPath() / getFilename(Core::getLanguage()));250 std::string filepath = PathConfig::getConfigPathString() + getFilename(Core::getLanguage()); 252 251 253 252 // Open the file 254 253 std::ifstream file; 255 file.open(filepath. string().c_str(), std::fstream::in);254 file.open(filepath.c_str(), std::fstream::in); 256 255 257 256 if (!file.is_open()) … … 303 302 COUT(4) << "Language: Write default language file." << std::endl; 304 303 305 boost::filesystem::path filepath(Core::getConfigPath() / getFilename(this->defaultLanguage_));304 std::string filepath = PathConfig::getConfigPathString() + getFilename(this->defaultLanguage_); 306 305 307 306 // Open the file 308 307 std::ofstream file; 309 file.open(filepath. string().c_str(), std::fstream::out);308 file.open(filepath.c_str(), std::fstream::out); 310 309 311 310 if (!file.is_open()) -
code/trunk/src/libraries/core/Loader.cc
r5781 r5929 103 103 { 104 104 if (mask.isIncluded(it->getIdentifier())) 105 delete (*(it++));105 (it++)->destroy(); 106 106 else 107 107 ++it; … … 204 204 { 205 205 if ((it->getFile() == file) && mask.isIncluded(it->getIdentifier())) 206 delete (*(it++));206 (it++)->destroy(); 207 207 else 208 208 ++it; -
code/trunk/src/libraries/core/LuaState.cc
r5781 r5929 37 37 38 38 #include "util/Debug.h" 39 #include "Core.h"40 39 #include "Resource.h" 41 40 #include "ToluaBindCore.h" -
code/trunk/src/libraries/core/MemoryArchive.cc
r5781 r5929 68 68 continue; 69 69 if (bDirs) 70 file = file. parent_path();70 file = file.branch_path(); 71 71 if (file.empty()) 72 72 continue; 73 if (file.has_ parent_path() && !bRecursive)73 if (file.has_branch_path() && !bRecursive) 74 74 continue; 75 75 if (simpleList) … … 80 80 fi.archive = this; 81 81 fi.filename = file.string(); 82 fi.basename = file. filename();83 fi.path = file. parent_path().string();82 fi.basename = file.leaf(); 83 fi.path = file.branch_path().string(); 84 84 fi.compressedSize = it->second.second; 85 85 fi.uncompressedSize = it->second.second; … … 119 119 120 120 bool MemoryArchive::exists(const String& filename) 121 121 { 122 122 const FileMap& files = archives_s[this->getName()]; 123 123 return files.find(filename) != files.end(); 124 124 } 125 125 126 126 const Ogre::String& MemoryArchiveFactory::getType(void) const -
code/trunk/src/libraries/core/ObjectListIterator.h
r5738 r5929 123 123 inline const ObjectListIterator<T>& operator++() 124 124 { 125 if (this->element_) 126 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_); 125 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_); 127 126 return *this; 128 127 } … … 135 134 { 136 135 ObjectListIterator<T> copy = *this; 137 if (this->element_) 138 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_); 136 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_); 139 137 return copy; 140 138 } … … 146 144 inline const ObjectListIterator<T>& operator--() 147 145 { 148 if (this->element_) 149 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_); 146 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_); 150 147 return *this; 151 148 } … … 158 155 { 159 156 ObjectListIterator<T> copy = *this; 160 if (this->element_) 161 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_); 157 this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_); 162 158 return copy; 163 159 } … … 169 165 inline T* operator*() const 170 166 { 171 if (this->element_) 172 return this->element_->object_; 173 else 174 return 0; 167 return this->element_->object_; 175 168 } 176 169 … … 181 174 inline T* operator->() const 182 175 { 183 if (this->element_) 184 return this->element_->object_; 185 else 186 return 0; 176 return this->element_->object_; 187 177 } 188 178 -
code/trunk/src/libraries/core/OrxonoxClass.cc
r5738 r5929 36 36 #include "MetaObjectList.h" 37 37 #include "Identifier.h" 38 #include "WeakPtr.h" 38 39 39 40 namespace orxonox … … 45 46 this->parents_ = 0; 46 47 this->metaList_ = new MetaObjectList(); 48 this->referenceCount_ = 0; 49 this->requestedDestruction_ = false; 47 50 } 48 51 … … 50 53 OrxonoxClass::~OrxonoxClass() 51 54 { 55 // if (!this->requestedDestruction_) 56 // COUT(2) << "Warning: Destroyed object without destroy() (" << this->getIdentifier()->getName() << ")" << std::endl; 57 58 assert(this->referenceCount_ <= 0); 59 52 60 delete this->metaList_; 53 61 … … 55 63 if (this->parents_) 56 64 delete this->parents_; 65 66 // reset all weak pointers pointing to this object 67 for (std::set<WeakPtr<OrxonoxClass>*>::iterator it = this->weakPointers_.begin(); it != this->weakPointers_.end(); ) 68 (*(it++))->objectDeleted(); 69 } 70 71 /** @brief Deletes the object if no smart pointers point to this object. Otherwise schedules the object to be deleted as soon as possible. */ 72 void OrxonoxClass::destroy() 73 { 74 this->requestedDestruction_ = true; 75 if (this->referenceCount_ == 0) 76 delete this; 57 77 } 58 78 … … 78 98 79 99 /** @brief Returns true if the objects class is of the given type or a derivative. */ 80 template <class B> bool OrxonoxClass::isA(const SubclassIdentifier<B>* identifier)81 { return this->getIdentifier()->isA(identifier->getIdentifier()); }82 /** @brief Returns true if the objects class is exactly of the given type. */83 template <class B> bool OrxonoxClass::isExactlyA(const SubclassIdentifier<B>* identifier)84 { return this->getIdentifier()->isExactlyA(identifier->getIdentifier()); }85 /** @brief Returns true if the objects class is a child of the given type. */86 template <class B> bool OrxonoxClass::isChildOf(const SubclassIdentifier<B>* identifier)87 { return this->getIdentifier()->isChildOf(identifier->getIdentifier()); }88 /** @brief Returns true if the objects class is a direct child of the given type. */89 template <class B> bool OrxonoxClass::isDirectChildOf(const SubclassIdentifier<B>* identifier)90 { return this->getIdentifier()->isDirectChildOf(identifier->getIdentifier()); }91 /** @brief Returns true if the objects class is a parent of the given type. */92 template <class B> bool OrxonoxClass::isParentOf(const SubclassIdentifier<B>* identifier)93 { return this->getIdentifier()->isParentOf(identifier->getIdentifier()); }94 /** @brief Returns true if the objects class is a direct parent of the given type. */95 template <class B> bool OrxonoxClass::isDirectParentOf(const SubclassIdentifier<B>* identifier)96 { return this->getIdentifier()->isDirectParentOf(identifier->getIdentifier()); }97 98 99 /** @brief Returns true if the objects class is of the given type or a derivative. */100 template <class B> bool OrxonoxClass::isA(const SubclassIdentifier<B> identifier)101 { return this->getIdentifier()->isA(identifier.getIdentifier()); }102 /** @brief Returns true if the objects class is exactly of the given type. */103 template <class B> bool OrxonoxClass::isExactlyA(const SubclassIdentifier<B> identifier)104 { return this->getIdentifier()->isExactlyA(identifier.getIdentifier()); }105 /** @brief Returns true if the objects class is a child of the given type. */106 template <class B> bool OrxonoxClass::isChildOf(const SubclassIdentifier<B> identifier)107 { return this->getIdentifier()->isChildOf(identifier.getIdentifier()); }108 /** @brief Returns true if the objects class is a direct child of the given type. */109 template <class B> bool OrxonoxClass::isDirectChildOf(const SubclassIdentifier<B> identifier)110 { return this->getIdentifier()->isDirectChildOf(identifier.getIdentifier()); }111 /** @brief Returns true if the objects class is a parent of the given type. */112 template <class B> bool OrxonoxClass::isParentOf(const SubclassIdentifier<B> identifier)113 { return this->getIdentifier()->isParentOf(identifier.getIdentifier()); }114 /** @brief Returns true if the objects class is a direct parent of the given type. */115 template <class B> bool OrxonoxClass::isDirectParentOf(const SubclassIdentifier<B> identifier)116 { return this->getIdentifier()->isDirectParentOf(identifier.getIdentifier()); }117 118 119 /** @brief Returns true if the objects class is of the given type or a derivative. */120 100 bool OrxonoxClass::isA(const OrxonoxClass* object) 121 101 { return this->getIdentifier()->isA(object->getIdentifier()); } -
code/trunk/src/libraries/core/OrxonoxClass.h
r5738 r5929 55 55 friend class ClassIdentifier; 56 56 57 template <class T> 58 friend class SmartPtr; 59 60 template <class T> 61 friend class WeakPtr; 62 57 63 public: 58 64 OrxonoxClass(); 59 65 virtual ~OrxonoxClass(); 66 67 void destroy(); 60 68 61 69 /** @brief Function to collect the SetConfigValue-macro calls. */ … … 72 80 bool isDirectParentOf(const Identifier* identifier); 73 81 74 template <class B> bool isA(const SubclassIdentifier<B>* identifier); 75 template <class B> bool isExactlyA(const SubclassIdentifier<B>* identifier); 76 template <class B> bool isChildOf(const SubclassIdentifier<B>* identifier); 77 template <class B> bool isDirectChildOf(const SubclassIdentifier<B>* identifier); 78 template <class B> bool isParentOf(const SubclassIdentifier<B>* identifier); 79 template <class B> bool isDirectParentOf(const SubclassIdentifier<B>* identifier); 80 81 template <class B> bool isA(const SubclassIdentifier<B> identifier); 82 template <class B> bool isExactlyA(const SubclassIdentifier<B> identifier); 83 template <class B> bool isChildOf(const SubclassIdentifier<B> identifier); 84 template <class B> bool isDirectChildOf(const SubclassIdentifier<B> identifier); 85 template <class B> bool isParentOf(const SubclassIdentifier<B> identifier); 86 template <class B> bool isDirectParentOf(const SubclassIdentifier<B> identifier); 82 template <class B> inline bool isA(const SubclassIdentifier<B>* identifier) 83 { return this->isA(*identifier); } 84 template <class B> inline bool isExactlyA(const SubclassIdentifier<B>* identifier) 85 { return this->isExactlyA(*identifier); } 86 template <class B> inline bool isChildOf(const SubclassIdentifier<B>* identifier) 87 { return this->isChildOf(*identifier); } 88 template <class B> inline bool isDirectChildOf(const SubclassIdentifier<B>* identifier) 89 { return this->isDirectChildOf(*identifier); } 90 template <class B> inline bool isParentOf(const SubclassIdentifier<B>* identifier) 91 { return this->isParentOf(*identifier); } 92 template <class B> inline bool isDirectParentOf(const SubclassIdentifier<B>* identifier) 93 { return this->isDirectParentOf(*identifier); } 87 94 88 95 bool isA(const OrxonoxClass* object); … … 93 100 bool isDirectParentOf(const OrxonoxClass* object); 94 101 102 inline unsigned int getReferenceCount() const 103 { return this->referenceCount_; } 104 95 105 /** 96 106 @brief … … 100 110 Returns NULL if the no pointer was found. 101 111 */ 102 template <class T> 103 FORCEINLINE T* getDerivedPointer(unsigned int classID) 112 FORCEINLINE void* getDerivedPointer(unsigned int classID) 104 113 { 105 114 for (int i = this->objectPointers_.size() - 1; i >= 0; --i) 106 115 { 107 116 if (this->objectPointers_[i].first == classID) 108 return static_cast<T*>(this->objectPointers_[i].second);117 return this->objectPointers_[i].second; 109 118 } 110 119 return NULL; 111 120 } 112 //! Const version of getDerivedPointer 113 template <class T> 114 FORCEINLINE const T* getDerivedPointer(unsigned int classID) const 115 { 116 return const_cast<OrxonoxClass*>(this)->getDerivedPointer<T>(classID); 117 } 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); } 118 128 119 129 private: 130 /** @brief Increments the reference counter (for smart pointers). */ 131 inline void incrementReferenceCount() 132 { ++this->referenceCount_; } 133 /** @brief Decrements the reference counter (for smart pointers). */ 134 inline void decrementReferenceCount() 135 { --this->referenceCount_; if (this->referenceCount_ == 0 && this->requestedDestruction_) { delete this; } } 136 137 /** @brief Register a weak pointer which points to this object. */ 138 template <class T> 139 inline void registerWeakPtr(WeakPtr<T>* pointer) 140 { this->weakPointers_.insert(reinterpret_cast<WeakPtr<OrxonoxClass>*>(pointer)); } 141 /** @brief Unegister a weak pointer which pointed to this object before. */ 142 template <class T> 143 inline void unregisterWeakPtr(WeakPtr<T>* pointer) 144 { this->weakPointers_.erase(reinterpret_cast<WeakPtr<OrxonoxClass>*>(pointer)); } 145 120 146 Identifier* identifier_; //!< The Identifier of the object 121 147 std::set<const Identifier*>* parents_; //!< List of all parents of the object 122 148 MetaObjectList* metaList_; //!< MetaObjectList, containing all ObjectLists and ObjectListElements the object is registered in 149 int referenceCount_; //!< Counts the references from smart pointers to this object 150 bool requestedDestruction_; //!< Becomes true after someone called delete on this object 151 std::set<WeakPtr<OrxonoxClass>*> weakPointers_; //!< All weak pointers which point to this object (and like to get notified if it dies) 152 123 153 //! 'Fast map' that holds this-pointers of all derived types 124 154 std::vector<std::pair<unsigned int, void*> > objectPointers_; -
code/trunk/src/libraries/core/Resource.h
r5781 r5929 64 64 // Docs by Ogre::ResourceGroupManager.h 65 65 public: 66 66 /** 67 67 @brief 68 68 Open a single resource by name and return a DataStream … … 81 81 Shared pointer to data stream containing the data. Will be 82 82 destroyed automatically when no longer referenced. 83 83 */ 84 84 static DataStreamPtr open(const std::string& name, 85 85 const std::string& group = Resource::DEFAULT_GROUP, 86 86 bool bSearchGroupsIfNotFound = false); 87 87 88 88 /** 89 89 @brief 90 90 Open all resources matching a given pattern (which can contain … … 101 101 Shared pointer to a data stream list , will be 102 102 destroyed automatically when no longer referenced 103 103 */ 104 104 static DataStreamListPtr openMulti(const std::string& pattern, const std::string& group = Resource::DEFAULT_GROUP); 105 105 -
code/trunk/src/libraries/core/Shell.cc
r5781 r5929 88 88 OutputHandler::getOutStream().setOutputBuffer(0); 89 89 if (this->inputBuffer_) 90 delete this->inputBuffer_;90 this->inputBuffer_->destroy(); 91 91 } 92 92 -
code/trunk/src/libraries/core/Super.h
r5781 r5929 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/trunk/src/libraries/core/TclBind.cc
r5781 r5929 39 39 #include "CommandExecutor.h" 40 40 #include "ConsoleCommand.h" 41 #include " Core.h"41 #include "PathConfig.h" 42 42 #include "TclThreadManager.h" 43 43 … … 123 123 { 124 124 #ifdef DEPENDENCY_PACKAGE_ENABLE 125 if ( Core::isDevelopmentRun())125 if (PathConfig::isDevelopmentRun()) 126 126 return (std::string(specialConfig::dependencyLibraryDirectory) + "/tcl"); 127 127 else 128 return ( Core::getRootPathString() + "lib/tcl");128 return (PathConfig::getRootPathString() + "lib/tcl"); 129 129 #else 130 130 return ""; -
code/trunk/src/libraries/core/TclThreadManager.cc
r5781 r5929 36 36 #include <cpptcl/cpptcl.h> 37 37 38 #include "util/Clock.h" 38 39 #include "util/Convert.h" 39 40 #include "util/Exception.h" 40 #include "Clock.h"41 41 #include "CommandExecutor.h" 42 42 #include "ConsoleCommand.h" -
code/trunk/src/libraries/core/XMLPort.h
r5781 r5929 51 51 #include "util/MultiType.h" 52 52 #include "util/OrxAssert.h" 53 #include "Factory.h"54 53 #include "Identifier.h" 55 54 #include "Executor.h" … … 377 376 this->owner_->xmlAttributes_.clear(); 378 377 // Iterate through the attributes manually in order to make them case insensitive 379 Attribute* attribute = xmlelement.FirstAttribute(false);378 ticpp::Attribute* attribute = xmlelement.FirstAttribute(false); 380 379 while (attribute != 0) 381 380 { … … 412 411 } 413 412 } 414 else 413 else if (mode == XMLPort::SaveObject) 415 414 { 416 415 if (this->saveexecutor_) … … 548 547 for (ticpp::Iterator<ticpp::Element> child = xmlsubelement->FirstChildElement(false); child != child.end(); child++) 549 548 { 550 Identifier* identifier = Factory::getIdentifier(child->Value());549 Identifier* identifier = Identifier::getIdentifierByString(child->Value()); 551 550 if (identifier) 552 551 { … … 629 628 } 630 629 } 631 else 630 else if (mode == XMLPort::SaveObject) 632 631 { 633 632 } -
code/trunk/src/libraries/core/input/Button.cc
r5781 r5929 170 170 171 171 // evaluate the command 172 CommandEvaluationeval = CommandExecutor::evaluate(commandStr);172 const CommandEvaluation& eval = CommandExecutor::evaluate(commandStr); 173 173 if (!eval.isValid()) 174 174 { 175 parseError("Command evaluation failed.", true);175 parseError("Command evaluation of \"" + commandStr + "\"failed.", true); 176 176 continue; 177 177 } -
code/trunk/src/libraries/core/input/CMakeLists.txt
r5781 r5929 9 9 JoyStickQuantityListener.cc 10 10 KeyBinder.cc 11 KeyBinderManager.cc 11 12 Keyboard.cc 12 13 KeyDetector.cc -
code/trunk/src/libraries/core/input/InputDevice.h
r5781 r5929 41 41 #include <ois/OISInputManager.h> 42 42 43 #include "util/Clock.h" 43 44 #include "util/Debug.h" 44 45 #include "util/Exception.h" 45 #include "core/Clock.h"46 46 #include "InputState.h" 47 47 -
code/trunk/src/libraries/core/input/InputManager.cc
r5781 r5929 41 41 #include <boost/foreach.hpp> 42 42 43 #include "util/Clock.h" 43 44 #include "util/Convert.h" 44 45 #include "util/Exception.h" 45 46 #include "util/ScopeGuard.h" 46 #include "core/Clock.h"47 47 #include "core/CoreIncludes.h" 48 48 #include "core/ConfigValueIncludes.h" … … 53 53 54 54 #include "InputBuffer.h" 55 #include "KeyDetector.h"56 55 #include "JoyStick.h" 57 56 #include "JoyStickQuantityListener.h" … … 88 87 , oisInputManager_(0) 89 88 , devices_(2) 90 , bExclusiveMouse_(false)89 , mouseMode_(MouseMode::Nonexclusive) 91 90 , emptyState_(0) 92 , keyDetector_(0)93 91 , calibratorCallbackHandler_(0) 94 92 { … … 99 97 this->setConfigValues(); 100 98 99 if (GraphicsManager::getInstance().isFullScreen()) 100 mouseMode_ = MouseMode::Exclusive; 101 101 this->loadDevices(); 102 102 … … 105 105 emptyState_->setHandler(&InputHandler::EMPTY); 106 106 activeStates_[emptyState_->getPriority()] = emptyState_; 107 108 // KeyDetector to evaluate a pressed key's name109 InputState* detector = createInputState("detector", false, false, InputStatePriority::Detector);110 // Create a callback to avoid buttonHeld events after the key has been detected111 FunctorMember<InputManager>* bufferFunctor = createFunctor(&InputManager::clearBuffers);112 bufferFunctor->setObject(this);113 detector->setLeaveFunctor(bufferFunctor);114 keyDetector_ = new KeyDetector();115 detector->setHandler(keyDetector_);116 107 117 108 // Joy stick calibration helper callback … … 124 115 this->updateActiveStates(); 125 116 126 { 127 // calibrate console command 128 FunctorMember<InputManager>* functor = createFunctor(&InputManager::calibrate); 129 functor->setObject(this); 130 this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "calibrate"), true); 131 } 132 { 133 // reload console command 134 FunctorMember<InputManager>* functor = createFunctor(&InputManager::reload); 135 functor->setObject(this); 136 this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "reload"), false); 137 } 117 // calibrate console command 118 this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&InputManager::calibrate, this), "calibrate"), true); 119 // reload console command 120 this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&InputManager::reload, this), "reload"), false); 138 121 139 122 CCOUT(4) << "Construction complete." << std::endl; … … 172 155 paramList.insert(std::make_pair("w32_keyboard", "DISCL_FOREGROUND")); 173 156 paramList.insert(std::make_pair("w32_mouse", "DISCL_FOREGROUND")); 174 if ( bExclusiveMouse_|| GraphicsManager::getInstance().isFullScreen())157 if (mouseMode_ == MouseMode::Exclusive || GraphicsManager::getInstance().isFullScreen()) 175 158 { 176 159 // Disable Windows key plus special keys (like play, stop, next, etc.) … … 185 168 paramList.insert(std::make_pair("XAutoRepeatOn", "true")); 186 169 187 if ( bExclusiveMouse_|| GraphicsManager::getInstance().isFullScreen())170 if (mouseMode_ == MouseMode::Exclusive || GraphicsManager::getInstance().isFullScreen()) 188 171 { 189 172 if (CommandLine::getValue("keyboard_no_grab").getBool()) … … 274 257 } 275 258 276 void InputManager::setKeyDetectorCallback(const std::string& command)277 {278 this->keyDetector_->setCallbackCommand(command);279 }280 281 259 // ############################################################ 282 260 // ##### Destruction ##### … … 289 267 290 268 // Destroy calibrator helper handler and state 291 delete keyDetector_;292 269 this->destroyState("calibrator"); 293 270 // Destroy KeyDetector and state 294 delete calibratorCallbackHandler_; 295 this->destroyState("detector"); 271 calibratorCallbackHandler_->destroy(); 296 272 // destroy the empty InputState 297 273 this->destroyStateInternal(this->emptyState_); … … 528 504 529 505 // Check whether we have to change the mouse mode 506 MouseMode::Value requestedMode = MouseMode::Dontcare; 530 507 std::vector<InputState*>& mouseStates = devices_[InputDeviceEnumerator::Mouse]->getStateListRef(); 531 if (mouseStates.empty() && bExclusiveMouse_ || 532 !mouseStates.empty() && mouseStates.front()->getIsExclusiveMouse() != bExclusiveMouse_) 533 { 534 bExclusiveMouse_ = !bExclusiveMouse_; 508 if (mouseStates.empty()) 509 requestedMode = MouseMode::Nonexclusive; 510 else 511 requestedMode = mouseStates.front()->getMouseMode(); 512 if (requestedMode != MouseMode::Dontcare && mouseMode_ != requestedMode) 513 { 514 mouseMode_ = requestedMode; 535 515 if (!GraphicsManager::getInstance().isFullScreen()) 536 516 this->reloadInternal(); … … 722 702 } 723 703 statesByName_.erase(state->getName()); 724 delete state;704 state->destroy(); 725 705 } 726 706 } -
code/trunk/src/libraries/core/input/InputManager.h
r5781 r5929 161 161 // Various getters and setters 162 162 //------------------------------- 163 //! Sets the the name of the command used by the KeyDetector as callback.164 void setKeyDetectorCallback(const std::string& command);165 163 //! Returns the number of joy stick that have been created since the c'tor or last call to reload(). 166 164 unsigned int getJoyStickQuantity() const … … 193 191 OIS::InputManager* oisInputManager_; //!< OIS input manager 194 192 std::vector<InputDevice*> devices_; //!< List of all input devices (keyboard, mouse, joy sticks) 195 bool bExclusiveMouse_;//!< Currently applied mouse mode193 MouseMode::Value mouseMode_; //!< Currently applied mouse mode 196 194 197 195 // some internally handled states and handlers 198 196 InputState* emptyState_; //!< Lowest priority states (makes handling easier) 199 KeyDetector* keyDetector_; //!< KeyDetector instance200 197 //! InputBuffer that reacts to the Enter key when calibrating the joy sticks 201 198 InputBuffer* calibratorCallbackHandler_; -
code/trunk/src/libraries/core/input/InputState.cc
r5781 r5929 37 37 , bAlwaysGetsInput_(bAlwaysGetsInput) 38 38 , bTransparent_(bTransparent) 39 , bExclusiveMouse_(true)39 , mouseMode_(MouseMode::Dontcare) 40 40 , bExpired_(true) 41 41 , handlers_(2) -
code/trunk/src/libraries/core/input/InputState.h
r5781 r5929 55 55 static const int Detector = HighPriority + 2; 56 56 }; 57 58 namespace MouseMode 59 { 60 enum Value 61 { 62 Exclusive, 63 Nonexclusive, 64 Dontcare 65 }; 66 } 57 67 58 68 /** … … 120 130 void setHandler (InputHandler* handler); 121 131 122 void set IsExclusiveMouse(bool value) { bExclusiveMouse_ = value; this->bExpired_ = true; }123 bool getIsExclusiveMouse() const { return bExclusiveMouse_; }132 void setMouseMode(MouseMode::Value value) { mouseMode_ = value; this->bExpired_ = true; } 133 MouseMode::Value getMouseMode() const { return mouseMode_; } 124 134 125 135 //! Returns the name of the state (which is unique!) … … 174 184 const bool bAlwaysGetsInput_; //!< See class declaration for explanation 175 185 const bool bTransparent_; //!< See class declaration for explanation 176 bool bExclusiveMouse_;//!< See class declaration for explanation186 MouseMode::Value mouseMode_; //!< See class declaration for explanation 177 187 int priority_; //!< Current priority (might change) 178 188 bool bExpired_; //!< See hasExpired() -
code/trunk/src/libraries/core/input/KeyBinder.cc
r5781 r5929 27 27 */ 28 28 29 /**30 @file31 @brief Implementation of the different input handlers.32 */33 34 29 #include "KeyBinder.h" 35 30 36 31 #include "util/Convert.h" 37 32 #include "util/Debug.h" 33 #include "util/Exception.h" 38 34 #include "core/ConfigValueIncludes.h" 39 35 #include "core/CoreIncludes.h" … … 48 44 Constructor that does as little as necessary. 49 45 */ 50 KeyBinder::KeyBinder( )46 KeyBinder::KeyBinder(const std::string& filename) 51 47 : deriveTime_(0.0f) 48 , filename_(filename) 52 49 { 53 50 mouseRelative_[0] = 0; … … 103 100 // set them here to use allHalfAxes_ 104 101 setConfigValues(); 102 103 // Load the bindings if filename was given 104 if (!this->filename_.empty()) 105 this->loadBindings(); 105 106 } 106 107 … … 240 241 @brief 241 242 Loads the key and button bindings. 242 @return 243 True if loading succeeded. 244 */ 245 void KeyBinder::loadBindings(const std::string& filename) 243 */ 244 void KeyBinder::loadBindings() 246 245 { 247 246 COUT(3) << "KeyBinder: Loading key bindings..." << std::endl; 248 247 249 if (filename.empty()) 250 return; 251 252 if (this->configFile_ == ConfigFileType::NoType) 253 { 254 // Get a new ConfigFileType from the ConfigFileManager 255 this->configFile_ = ConfigFileManager::getInstance().getNewConfigFileType(); 256 } 257 258 ConfigFileManager::getInstance().setFilename(this->configFile_, filename); 248 // Get a new ConfigFileType from the ConfigFileManager 249 this->configFile_ = ConfigFileManager::getInstance().getNewConfigFileType(); 250 251 ConfigFileManager::getInstance().setFilename(this->configFile_, this->filename_); 259 252 260 253 // Parse bindings and create the ConfigValueContainers if necessary 261 clearBindings();262 254 for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it) 263 255 it->second->readConfigValue(this->configFile_); -
code/trunk/src/libraries/core/input/KeyBinder.h
r5781 r5929 26 26 * 27 27 */ 28 29 /**30 @file31 @brief32 Different definitions of input processing.33 */34 28 35 29 #ifndef _KeyBinder_H__ … … 53 47 /** 54 48 @brief 55 Handles mouse, keyboard and joy stick input while in the actual game mode. 56 Manages the key bindings. 49 Maps mouse, keyboard and joy stick input to command strings and executes them. 50 51 The bindings are stored in ini-files (like the one for configValues) in the config Path. 52 @remarks 53 You cannot change the filename because the KeyBinderManager maps these filenames to the 54 KeyBinders. If you need to load other bindings, just create a new one. 57 55 */ 58 56 class _CoreExport KeyBinder : public InputHandler, public JoyStickQuantityListener 59 57 { 60 58 public: 61 KeyBinder ( );59 KeyBinder (const std::string& filename); 62 60 virtual ~KeyBinder(); 63 61 64 void loadBindings(const std::string& filename);65 62 void clearBindings(); 66 63 bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false); 64 const std::string& getBindingsFilename() 65 { return this->filename_; } 67 66 void setConfigValues(); 68 67 void resetJoyStickAxes(); 69 68 70 69 protected: // functions 70 void loadBindings(); 71 void buttonThresholdChanged(); 72 void initialiseJoyStickBindings(); 73 void compilePointerLists(); 74 // from JoyStickQuantityListener interface 75 virtual void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList); 76 71 77 void allDevicesUpdated(float dt); 72 78 void mouseUpdated(float dt); … … 74 80 // internal 75 81 void tickHalfAxis(HalfAxis& halfAxis); 76 77 void buttonThresholdChanged();78 // from JoyStickQuantityListener interface79 virtual void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);80 void initialiseJoyStickBindings();81 void compilePointerLists();82 82 83 83 void buttonPressed (const KeyEvent& evt); … … 144 144 float deriveTime_; 145 145 146 //! Name of the file used in this KeyBinder (constant!) 147 const std::string filename_; 146 148 //! Config file used. ConfigFileType::NoType in case of KeyDetector. Also indicates whether we've already loaded. 147 149 ConfigFileType configFile_; … … 171 173 }; 172 174 175 173 176 inline void KeyBinder::buttonPressed (const KeyEvent& evt) 174 177 { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnPress); } -
code/trunk/src/libraries/core/input/KeyDetector.cc
r5781 r5929 29 29 #include "KeyDetector.h" 30 30 31 #include " util/Debug.h"31 #include "core/ConsoleCommand.h" 32 32 #include "core/CoreIncludes.h" 33 #include "core/ScopedSingletonManager.h" 33 34 #include "Button.h" 35 #include "InputManager.h" 36 #include "InputState.h" 34 37 35 38 namespace orxonox 36 39 { 37 /**38 @brief39 Constructor40 */ 40 std::string KeyDetector::callbackCommand_s = "KeyDetectorKeyPressed"; 41 KeyDetector* KeyDetector::singletonPtr_s = 0; 42 ManageScopedSingleton(KeyDetector, ScopeID::Graphics, false); 43 41 44 KeyDetector::KeyDetector() 45 : KeyBinder("") 42 46 { 43 47 RegisterObject(KeyDetector); 48 49 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyDetector::callback, this), callbackCommand_s)); 50 this->assignCommands(); 51 52 inputState_ = InputManager::getInstance().createInputState("detector", false, false, InputStatePriority::Detector); 53 // Create a callback to avoid buttonHeld events after the key has been detected 54 inputState_->setLeaveFunctor(createFunctor(&InputManager::clearBuffers, &InputManager::getInstance())); 55 inputState_->setHandler(this); 44 56 } 45 57 46 /**47 @brief48 Destructor49 */50 58 KeyDetector::~KeyDetector() 51 59 { 60 inputState_->setHandler(NULL); 61 InputManager::getInstance().destroyState("detector"); 52 62 } 53 63 54 /** 55 @brief 56 Assigns all the buttons 'command' plus the button's name. 57 */ 58 void KeyDetector::setCallbackCommand(const std::string& command) 64 void KeyDetector::assignCommands() 59 65 { 60 callbackCommand_ = command;66 // Assign every button/axis the same command, but with its name as argument 61 67 clearBindings(); 62 68 for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it) 63 69 { 64 it->second->bindingString_ = callbackCommand_ + it->second->groupName_ + "." + it->second->name_;70 it->second->bindingString_ = callbackCommand_s + " " + it->second->groupName_ + "." + it->second->name_; 65 71 it->second->parse(); 66 72 } 73 } 74 75 void KeyDetector::callback(const std::string& name) 76 { 77 // Call the registered function 78 if (this->callbackFunction_) 79 (*this->callbackFunction_)(name); 67 80 } 68 81 … … 70 83 { 71 84 KeyBinder::JoyStickQuantityChanged(joyStickList); 72 if (!callbackCommand_.empty()) 73 setCallbackCommand(callbackCommand_); 85 this->assignCommands(); 74 86 } 75 87 } -
code/trunk/src/libraries/core/input/KeyDetector.h
r5781 r5929 32 32 #include "InputPrereqs.h" 33 33 34 #include <string>34 #include "util/Singleton.h" 35 35 #include "KeyBinder.h" 36 36 37 37 namespace orxonox 38 38 { 39 class _CoreExport KeyDetector : public KeyBinder 39 class _CoreExport KeyDetector : public KeyBinder, public Singleton<KeyDetector> 40 40 { 41 friend class Singleton<KeyDetector>; 42 41 43 public: 42 44 KeyDetector(); 43 45 ~KeyDetector(); 44 void setCallbackCommand(const std::string& command); 45 void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);46 47 void setCallback(Functor* function) { this->callbackFunction_ = function; } 46 48 47 49 private: 48 std::string callbackCommand_; 50 KeyDetector(const KeyDetector&); 51 52 void callback(const std::string& name); 53 void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList); 54 void assignCommands(); 55 56 Functor* callbackFunction_; 57 InputState* inputState_; 58 static std::string callbackCommand_s; 59 static KeyDetector* singletonPtr_s; 49 60 }; 50 61 } -
code/trunk/src/libraries/core/input/Mouse.cc
r5781 r5929 48 48 49 49 #ifdef ORXONOX_PLATFORM_LINUX 50 { 51 // Mouse grab console command 52 FunctorMember<Mouse>* functor = createFunctor(&Mouse::grab); 53 functor->setObject(this); 54 this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "grab"), false); 55 } 56 { 57 // Mouse ungrab console command 58 FunctorMember<Mouse>* functor = createFunctor(&Mouse::ungrab); 59 functor->setObject(this); 60 this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "ungrab"), false); 61 } 50 // Mouse grab console command 51 this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&Mouse::grab, this), "grab"), false); 52 // Mouse ungrab console command 53 this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&Mouse::ungrab, this), "ungrab"), false); 62 54 #endif 63 55 } -
code/trunk/src/libraries/network/Client.cc
r5781 r5929 43 43 #include <cassert> 44 44 45 #include "util/Clock.h" 45 46 #include "util/Debug.h" 46 #include "core/Clock.h"47 47 #include "synchronisable/Synchronisable.h" 48 48 #include "packet/Chat.h" 49 49 #include "packet/Gamestate.h" 50 50 #include "FunctionCallManager.h" 51 #include "core/CoreIncludes.h" 52 #include "core/Game.h" 51 53 52 54 namespace orxonox … … 158 160 return; 159 161 } 162 163 void Client::connectionClosed() 164 { 165 ObjectList<Synchronisable>::iterator it; 166 for(it = ObjectList<Synchronisable>::begin(); it; ) 167 { 168 if( it->getSyncMode() != 0x0 ) 169 (it++)->destroy(); 170 else 171 { 172 ++it; 173 } 174 } 175 Game::getInstance().popState(); 176 Game::getInstance().popState(); 177 } 160 178 161 179 } -
code/trunk/src/libraries/network/Client.h
r5781 r5929 45 45 46 46 #include <string> 47 48 #include "util/UtilPrereqs.h" 47 49 #include "ClientConnection.h" 48 50 #include "GamestateClient.h" … … 72 74 73 75 void update(const Clock& time); 74 76 protected: 77 virtual void connectionClosed(); 75 78 private: 76 79 Client(const Client& copy); // not used -
code/trunk/src/libraries/network/ClientConnection.cc
r5781 r5929 118 118 case ENET_EVENT_TYPE_DISCONNECT: 119 119 COUT(4) << "received disconnect confirmation from server" << endl; 120 this->connectionClosed(); 120 121 return true; 121 122 } … … 123 124 } 124 125 enet_peer_reset( this->server_ ); 126 this->connectionClosed(); 125 127 return false; 126 128 } … … 133 135 } 134 136 135 void ClientConnection::add Client(ENetEvent* event)137 void ClientConnection::addPeer(ENetEvent* event) 136 138 { 137 139 assert(0); 138 140 } 139 void ClientConnection:: disconnectPeer(ENetEvent* event)141 void ClientConnection::removePeer(ENetEvent* event) 140 142 { 141 143 this->established_=false; 142 144 COUT(1) << "Received disconnect Packet from Server!" << endl; 143 145 // server closed the connection 146 this->connectionClosed(); 144 147 } 145 148 -
code/trunk/src/libraries/network/ClientConnection.h
r5781 r5929 53 53 bool addPacket(ENetPacket *packet); 54 54 inline bool isConnected(){ return this->established_; } 55 protected: 56 virtual void connectionClosed()=0; 55 57 private: 56 virtual void add Client(ENetEvent* event);57 virtual void disconnectPeer(ENetEvent* event);58 virtual void addPeer(ENetEvent* event); 59 virtual void removePeer(ENetEvent* event); 58 60 59 61 bool disconnectConnection(); -
code/trunk/src/libraries/network/ClientConnectionListener.cc
r5781 r5929 33 33 #include "ClientInformation.h" 34 34 35 namespace orxonox{ 35 namespace orxonox 36 { 37 ClientConnectionListener::ClientConnectionListener() 38 { 39 RegisterRootObject(ClientConnectionListener); 40 } 36 41 37 ClientConnectionListener::ClientConnectionListener() 38 { 39 RegisterRootObject(ClientConnectionListener); 40 } 42 void ClientConnectionListener::broadcastClientConnected(unsigned int clientID) 43 { 44 for (ObjectList<ClientConnectionListener>::iterator it = ObjectList<ClientConnectionListener>::begin(); it != ObjectList<ClientConnectionListener>::end(); ++it) 45 it->clientConnected(clientID); 46 } 47 48 void ClientConnectionListener::broadcastClientDisconnected(unsigned int clientID) 49 { 50 for (ObjectList<ClientConnectionListener>::iterator it = ObjectList<ClientConnectionListener>::begin(); it != ObjectList<ClientConnectionListener>::end(); ++it) 51 it->clientDisconnected(clientID); 52 } 41 53 42 void ClientConnectionListener::getConnectedClients(){ 43 if(GameMode::showsGraphics()) 44 this->clientConnected(0); //server client id 45 ClientInformation *client = ClientInformation::getBegin(); 46 while(client){ 47 this->clientConnected(client->getID()); 48 client=client->next(); 54 void ClientConnectionListener::getConnectedClients() 55 { 56 ClientInformation* client = ClientInformation::getBegin(); 57 while (client) 58 { 59 this->clientConnected(client->getID()); 60 client = client->next(); 61 } 49 62 } 50 }51 52 63 } 53 64 -
code/trunk/src/libraries/network/ClientConnectionListener.h
r5781 r5929 33 33 #include "core/OrxonoxClass.h" 34 34 35 namespace orxonox{ 35 namespace orxonox 36 { 37 class _NetworkExport ClientConnectionListener : virtual public OrxonoxClass 38 { 39 public: 40 ClientConnectionListener(); 41 virtual ~ClientConnectionListener() {} 42 43 static void broadcastClientConnected(unsigned int clientID); 44 static void broadcastClientDisconnected(unsigned int clientID); 36 45 37 class _NetworkExport ClientConnectionListener : virtual public OrxonoxClass 38 { 39 friend class Server; 46 virtual void clientConnected(unsigned int clientID) = 0; 47 virtual void clientDisconnected(unsigned int clientID) = 0; 40 48 41 public: 42 ClientConnectionListener(); 43 virtual ~ClientConnectionListener() {} 44 45 void getConnectedClients(); 46 47 protected: 48 virtual void clientConnected(unsigned int clientID) = 0; 49 virtual void clientDisconnected(unsigned int clientID) = 0; 50 }; 51 49 protected: 50 void getConnectedClients(); 51 }; 52 52 } 53 53 -
code/trunk/src/libraries/network/Connection.cc
- Property svn:eol-style set to native
r5781 r5929 83 83 // log handling ================ 84 84 case ENET_EVENT_TYPE_CONNECT: 85 add Client( &event );85 addPeer( &event ); 86 86 break; 87 87 case ENET_EVENT_TYPE_DISCONNECT: 88 disconnectPeer( &event );88 removePeer( &event ); 89 89 break; 90 90 case ENET_EVENT_TYPE_RECEIVE: -
code/trunk/src/libraries/network/Connection.h
- Property svn:eol-style set to native
r5781 r5929 64 64 65 65 int service(ENetEvent* event); 66 v oid disconnectPeer(ENetPeer *peer);66 virtual void disconnectPeer(ENetPeer *peer); 67 67 68 68 void processQueue(); 69 virtual void add Client(ENetEvent* event)=0;70 virtual void disconnectPeer(ENetEvent* event)=0;69 virtual void addPeer(ENetEvent* event)=0; 70 virtual void removePeer(ENetEvent* event)=0; 71 71 virtual bool processPacket(ENetEvent* event); 72 72 -
code/trunk/src/libraries/network/GamestateClient.cc
r5781 r5929 108 108 ObjectList<Synchronisable>::iterator temp=it; 109 109 ++it; 110 delete *temp;110 temp->destroy(); // or delete? 111 111 } 112 112 -
code/trunk/src/libraries/network/GamestateManager.cc
r5781 r5929 77 77 delete (*it2).second; 78 78 } 79 delete this->trafficControl_;79 this->trafficControl_->destroy(); 80 80 // delete this->threadMutex_; 81 81 // delete this->threadPool_; … … 160 160 finishGamestate( cid, &clientGamestates.back(), client, reference ); 161 161 //FunctorMember<GamestateManager>* functor = 162 // ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate) ); 163 // executor->setObject(this); 162 // ExecutorMember<GamestateManager>* executor = createExecutor( createFunctor(&GamestateManager::finishGamestate, this) ); 164 163 // executor->setDefaultValues( cid, &clientGamestates.back(), client, reference ); 165 164 // (*static_cast<Executor*>(executor))(); -
code/trunk/src/libraries/network/NetworkFunction.cc
r5781 r5929 60 60 std::map<std::string, NetworkFunctionBase*>::iterator it; 61 61 for( it=NetworkFunctionBase::nameMap_.begin(); it!=NetworkFunctionBase::nameMap_.end(); ++it ) 62 delete it->second;62 it->second->destroy(); 63 63 } 64 64 -
code/trunk/src/libraries/network/NetworkPrereqs.h
r5781 r5929 28 28 29 29 /** 30 @file 31 @brief Contains all the necessary forward declarations for all classes and structs. 30 @file 31 @brief 32 Shared library macros, enums, constants and forward declarations for the network library 32 33 */ 33 34 … … 40 41 // Shared library settings 41 42 //----------------------------------------------------------------------- 43 42 44 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined( NETWORK_STATIC_BUILD ) 43 45 # ifdef NETWORK_SHARED_BUILD … … 57 59 58 60 //----------------------------------------------------------------------- 59 // Library global contants61 // Constants 60 62 //----------------------------------------------------------------------- 63 61 64 namespace orxonox 62 65 { 63 66 static const unsigned int GAMESTATEID_INITIAL = static_cast<unsigned int>(-1); 64 67 static const unsigned int CLIENTID_UNKNOWN = static_cast<unsigned int>(-2); 65 static const uint32_t OBJECTID_UNKNOWN = static_cast<uint32_t>(-1); 68 } 69 70 //----------------------------------------------------------------------- 71 // Enums 72 //----------------------------------------------------------------------- 73 74 namespace orxonox 75 { 76 namespace packet 77 { 78 namespace PacketFlag 79 { 80 enum Value 81 { 82 Reliable = 1, 83 Unsequence = 2, 84 NoAllocate = 4 85 }; 86 } 87 } 66 88 } 67 89 … … 84 106 namespace orxonox 85 107 { 108 class ChatListener; 86 109 class Client; 87 110 class ClientConnection; 88 111 class ClientConnectionListener; 89 class ClientFrameListener;90 112 class ClientInformation; 91 113 class Connection; 92 114 class FunctionCallManager; 93 115 class GamestateClient; 116 class GamestateHandler; 94 117 class GamestateManager; 95 class GamestateHandler; 96 class NetworkCallbackBase; 97 template <class T> class NetworkCallback; 98 class NetworkCallbackManager; 118 class Host; 99 119 class NetworkFunctionBase; 120 struct NetworkFunctionPointer; 100 121 class NetworkFunctionStatic; 122 template <class T> 123 class NetworkMemberFunction; 101 124 class NetworkMemberFunctionBase; 102 template <class T> class NetworkMemeberFunction;103 struct NetworkFunctionPointer;104 125 class Server; 105 126 class ServerConnection; 106 class ServerFrameListener;107 class Synchronisable;108 class SynchronisableVariableBase;109 template <class T> class SynchronisableVariable;110 template <class T> class SynchronisableVariableBidirectional;111 struct ClientList;112 struct PacketEnvelope;113 struct QueueItem;114 struct syncData;115 127 class TrafficControl; 116 class obj;117 class objInfo;118 128 129 // packet 119 130 namespace packet 120 131 { … … 122 133 class Chat; 123 134 class ClassID; 135 class DeleteObjects; 124 136 class FunctionCalls; 125 137 class FunctionIDs; 126 138 class Gamestate; 127 class NetworkIDs;128 139 class Packet; 129 140 class Welcome; 141 } 130 142 131 namespace PacketFlag 132 { 133 enum Value 134 { 135 Reliable = 1, 136 Unsequence = 2, 137 NoAllocate = 4 138 }; 139 } 140 } 143 // synchronisable 144 template <class T> 145 class NetworkCallback; 146 class NetworkCallbackBase; 147 class NetworkCallbackManager; 148 class Synchronisable; 149 class SynchronisableHeader; 150 template <class T> 151 class SynchronisableVariable; 152 class SynchronisableVariableBase; 153 template <class T> 154 class SynchronisableVariableBidirectional; 141 155 } 142 156 -
code/trunk/src/libraries/network/Server.cc
r5781 r5929 46 46 #include <string> 47 47 48 #include "util/Clock.h" 48 49 #include "util/Debug.h" 49 #include "core/Clock.h"50 50 #include "core/ObjectList.h" 51 51 #include "core/Executor.h" … … 245 245 packet::DeleteObjects *del = new packet::DeleteObjects(); 246 246 if(!del->fetchIDs()) 247 { 248 delete del; 247 249 return true; //everything ok (no deletes this tick) 250 } 248 251 // COUT(3) << "sending DeleteObjects" << std::endl; 249 252 while(temp != NULL){ … … 267 270 268 271 269 void Server::add Client(ENetEvent *event){272 void Server::addPeer(ENetEvent *event){ 270 273 static unsigned int newid=1; 271 274 … … 279 282 280 283 // inform all the listeners 281 ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin(); 282 while(listener){ 283 listener->clientConnected(newid); 284 listener++; 285 } 284 ClientConnectionListener::broadcastClientConnected(newid); 286 285 287 286 ++newid; … … 290 289 createClient(temp->getID()); 291 290 } 291 292 void Server::removePeer(ENetEvent *event) 293 { 294 COUT(4) << "removing client from list" << std::endl; 295 ClientInformation *client = ClientInformation::findClient(&event->peer->address); 296 if(!client) 297 return; 298 else 299 { 300 //ServerConnection::disconnectClient( client ); 301 ClientConnectionListener::broadcastClientDisconnected( client->getID() ); 302 delete client; 303 } 304 } 292 305 293 306 bool Server::createClient(int clientID){ … … 329 342 ServerConnection::disconnectClient( client ); 330 343 GamestateManager::removeClient(client); 331 // inform all the listeners 332 ObjectList<ClientConnectionListener>::iterator listener = ObjectList<ClientConnectionListener>::begin(); 333 while(listener){ 334 listener->clientDisconnected(client->getID()); 335 ++listener; 336 } 337 delete client; //remove client from list 344 // inform all the listeners 345 ClientConnectionListener::broadcastClientDisconnected(client->getID()); 338 346 } 339 347 -
code/trunk/src/libraries/network/Server.h
r5781 r5929 32 32 #include "NetworkPrereqs.h" 33 33 34 #include "util/UtilPrereqs.h" 34 35 #include "core/CorePrereqs.h" 35 36 #include "Host.h" … … 65 66 unsigned int playerID(){return 0;} 66 67 67 void addClient(ENetEvent *event); 68 void addPeer(ENetEvent *event); 69 void removePeer(ENetEvent *event); 70 68 71 bool createClient(int clientID); 69 72 void disconnectClient( ClientInformation *client); -
code/trunk/src/libraries/network/ServerConnection.cc
- Property svn:eol-style set to native
r5781 r5929 103 103 { 104 104 Connection::disconnectPeer( client->getPeer() ); 105 delete client;106 }107 108 void ServerConnection::disconnectPeer( ENetEvent* event )109 {110 COUT(4) << "removing client from list" << std::endl;111 ClientInformation *client = ClientInformation::findClient(&event->peer->address);112 if(!client)113 return;114 else115 ServerConnection::disconnectClient( client );116 105 } 117 106 … … 119 108 ClientInformation *client = ClientInformation::findClient(clientID); 120 109 if(client) 121 disconnectClient(client);110 ServerConnection::disconnectClient(client); 122 111 } 123 112 … … 126 115 ClientInformation *temp = ClientInformation::getBegin(); 127 116 while(temp!=0){ 128 disconnectClient( temp );117 ServerConnection::disconnectClient( temp ); 129 118 temp = temp->next(); 130 119 } … … 141 130 break; 142 131 case ENET_EVENT_TYPE_DISCONNECT: 143 if(ClientInformation::findClient(&(event.peer->address))) 144 delete ClientInformation::findClient(&(event.peer->address)); 132 removePeer( &event ); 145 133 temp = ClientInformation::getBegin(); 146 134 break; -
code/trunk/src/libraries/network/ServerConnection.h
- Property svn:eol-style set to native
r5781 r5929 59 59 static bool addPacketAll(ENetPacket *packet); 60 60 virtual void disconnectClient(ClientInformation *client); 61 void disconnectPeer( ENetEvent* event );62 61 void disconnectClient(int clientID); 63 62 protected: -
code/trunk/src/libraries/network/packet/CMakeLists.txt
r5781 r5929 1 1 ADD_SOURCE_FILES(NETWORK_SRC_FILES 2 COMPILATION_BEGIN PacketCompilation.cc 2 3 Acknowledgement.cc 3 4 Chat.cc … … 9 10 Packet.cc 10 11 Welcome.cc 12 COMPILATION_END 11 13 ) 12 14 -
code/trunk/src/libraries/network/packet/ClassID.cc
r5781 r5929 49 49 Identifier *id; 50 50 std::string classname; 51 unsigned int nrOfClasses=0; 51 unsigned int nrOfClasses=0; 52 52 unsigned int packetSize=2*sizeof(uint32_t); //space for the packetID and for the nrofclasses 53 53 uint32_t network_id; 54 54 flags_ = flags_ | PACKET_FLAGS_CLASSID; 55 55 std::queue<std::pair<uint32_t, std::string> > tempQueue; 56 56 57 57 //calculate total needed size (for all strings and integers) 58 std::map<std::string, Identifier*>::const_iterator it = Factory::getFactoryMapBegin();59 for(;it != Factory::getFactoryMapEnd();++it){58 std::map<std::string, Identifier*>::const_iterator it = Identifier::getStringIdentifierMapBegin(); 59 for(;it != Identifier::getStringIdentifierMapEnd();++it){ 60 60 id = (*it).second; 61 if(id == NULL )61 if(id == NULL || !id->hasFactory()) 62 62 continue; 63 63 classname = id->getName(); 64 64 network_id = id->getNetworkID(); 65 if(network_id==0)66 COUT(3) << "we got a null class id: " << id->getName() << std::endl;67 65 // now push the network id and the classname to the stack 68 66 tempQueue.push( std::pair<unsigned int, std::string>(network_id, classname) ); … … 70 68 packetSize += (classname.size()+1)+sizeof(uint32_t)+sizeof(uint32_t); 71 69 } 72 70 73 71 this->data_=new uint8_t[ packetSize ]; 74 72 //set the appropriate packet id 75 73 assert(this->data_); 76 74 *(Type::Value *)(this->data_ + _PACKETID ) = Type::ClassID; 77 75 78 76 uint8_t *temp=data_+sizeof(uint32_t); 79 77 // save the number of all classes 80 78 *(uint32_t*)temp = nrOfClasses; 81 79 temp += sizeof(uint32_t); 82 80 83 81 // now save all classids and classnames 84 82 std::pair<uint32_t, std::string> tempPair; … … 91 89 temp+=2*sizeof(uint32_t)+tempPair.second.size()+1; 92 90 } 93 91 94 92 COUT(5) << "classid packetSize is " << packetSize << endl; 95 93 96 94 } 97 95 … … 111 109 temp += sizeof(uint32_t); 112 110 totalsize += sizeof(uint32_t); // storage size for nr of all classes 113 111 114 112 for(unsigned int i=0; i<nrOfClasses; i++){ 115 113 totalsize += 2*sizeof(uint32_t) + *(uint32_t*)(temp + sizeof(uint32_t)); … … 125 123 uint32_t stringsize; 126 124 unsigned char *classname; 127 128 129 //clea nthe map of network ids130 Factory::cleanNetworkIDs();131 125 126 127 //clear the map of network ids 128 Identifier::clearNetworkIDs(); 129 132 130 COUT(4) << "=== processing classids: " << endl; 133 131 std::pair<uint32_t, std::string> tempPair; … … 136 134 nrOfClasses = *(uint32_t*)temp; 137 135 temp += sizeof(uint32_t); 138 136 139 137 for( int i=0; i<nrOfClasses; i++){ 140 138 networkID = *(uint32_t*)temp; -
code/trunk/src/libraries/network/packet/Gamestate.cc
r5781 r5929 378 378 rawDiff( dest2, dest, basep, header_->getDataSize(), base->header_->getDataSize() ); 379 379 assert( memcmp( dest2, gs, dest_length) == 0 ); 380 delete dest2; 380 381 #endif 381 382 -
code/trunk/src/libraries/network/synchronisable/Synchronisable.cc
r5781 r5929 47 47 /** 48 48 * Constructor: 49 * Initializes all Variables and sets the right objectID 49 * Initializes all Variables and sets the right objectID_ 50 50 */ 51 Synchronisable::Synchronisable(BaseObject* creator ){51 Synchronisable::Synchronisable(BaseObject* creator ){ 52 52 RegisterRootObject(Synchronisable); 53 53 static uint32_t idCounter=0; … … 55 55 if ( GameMode::isMaster() || ( Host::running() && Host::isServer() ) ) 56 56 { 57 this->objectID = idCounter++; //this is only needed when running a server 58 //add synchronisable to the objectMap 59 objectMap_[this->objectID] = this; 57 this->setObjectID( idCounter++ ); 60 58 } 61 59 else 62 60 { 63 objectID=OBJECTID_UNKNOWN; 64 this->setObjectMode(0x0); //make sure this object doesn't get synchronized 65 } 66 classID = static_cast<uint32_t>(-1); 61 objectID_=OBJECTID_UNKNOWN; 62 } 63 classID_ = static_cast<uint32_t>(-1); 67 64 68 65 // set dataSize to 0 … … 72 69 73 70 // get creator id 74 this->creatorID = OBJECTID_UNKNOWN; 75 76 searchcreatorID: 71 if( creator ) 72 this->creatorID_ = creator->getSceneID(); 73 else 74 this->creatorID_ = OBJECTID_UNKNOWN; 75 76 /*searchcreatorID: 77 77 if (creator) 78 78 { … … 80 80 if (synchronisable_creator && synchronisable_creator->objectMode_) 81 81 { 82 this->creatorID = synchronisable_creator->get ObjectID();82 this->creatorID = synchronisable_creator->getScene()->getObjectID(); 83 83 } 84 84 else if (creator != creator->getCreator()) … … 87 87 goto searchcreatorID; 88 88 } 89 } 89 }*/ 90 90 } 91 91 92 92 /** 93 93 * Destructor: 94 * Delete all callback objects and remove objectID from the objectMap_94 * Delete all callback objects and remove objectID_ from the objectMap_ 95 95 */ 96 96 Synchronisable::~Synchronisable(){ … … 99 99 // remove object from the static objectMap 100 100 if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer())) 101 deletedObjects_.push(objectID );101 deletedObjects_.push(objectID_); 102 102 } 103 103 // delete all Synchronisable Variables from syncList ( which are also in stringList ) … … 107 107 stringList.clear(); 108 108 std::map<uint32_t, Synchronisable*>::iterator it; 109 it = objectMap_.find(objectID );109 it = objectMap_.find(objectID_); 110 110 if (it != objectMap_.end()) 111 111 objectMap_.erase(it); … … 172 172 Synchronisable *no = orxonox_cast<Synchronisable*>(bo); 173 173 assert(no); 174 no->objectID=header.getObjectID(); 175 no->creatorID=header.getCreatorID(); //TODO: remove this 176 no->classID=header.getClassID(); 177 COUT(4) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl; 174 assert( Synchronisable::objectMap_.find(header.getObjectID()) == Synchronisable::objectMap_.end() ); 175 no->setObjectID(header.getObjectID()); 176 //no->creatorID=header.getCreatorID(); //TODO: remove this 177 no->setClassID(header.getClassID()); 178 assert(no->creatorID_ == header.getCreatorID()); 179 //assert(no->classID_ == header.getClassID()); 180 COUT(4) << "fabricate objectID_: " << no->objectID_ << " classID_: " << no->classID_ << std::endl; 178 181 // update data and create object/entity... 179 assert( Synchronisable::objectMap_.find(header.getObjectID()) == Synchronisable::objectMap_.end() );180 Synchronisable::objectMap_[header.getObjectID()] = no;181 182 bool b = no->updateData(mem, mode, true); 182 183 assert(b); … … 191 192 192 193 /** 193 * Finds and deletes the Synchronisable with the appropriate objectID 194 * @param objectID objectIDof the Synchronisable194 * Finds and deletes the Synchronisable with the appropriate objectID_ 195 * @param objectID_ objectID_ of the Synchronisable 195 196 * @return true/false 196 197 */ 197 bool Synchronisable::deleteObject(uint32_t objectID ){198 if(!getSynchronisable(objectID ))198 bool Synchronisable::deleteObject(uint32_t objectID_){ 199 if(!getSynchronisable(objectID_)) 199 200 return false; 200 assert(getSynchronisable(objectID )->objectID==objectID);201 Synchronisable *s = getSynchronisable(objectID );201 assert(getSynchronisable(objectID_)->objectID_==objectID_); 202 Synchronisable *s = getSynchronisable(objectID_); 202 203 if(s) 203 delete s;204 s->destroy(); // or delete? 204 205 else 205 206 return false; … … 208 209 209 210 /** 210 * This function looks up the objectID in the objectMap_ and returns a pointer to the right Synchronisable211 * @param objectID objectIDof the Synchronisable212 * @return pointer to the Synchronisable with the objectID 213 */ 214 Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID ){211 * This function looks up the objectID_ in the objectMap_ and returns a pointer to the right Synchronisable 212 * @param objectID_ objectID_ of the Synchronisable 213 * @return pointer to the Synchronisable with the objectID_ 214 */ 215 Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID_){ 215 216 std::map<uint32_t, Synchronisable*>::iterator it1; 216 it1 = objectMap_.find(objectID );217 it1 = objectMap_.find(objectID_); 217 218 if (it1 != objectMap_.end()) 218 219 return it1->second; … … 220 221 // ObjectList<Synchronisable>::iterator it; 221 222 // for(it = ObjectList<Synchronisable>::begin(); it; ++it){ 222 // if( it->getObjectID()==objectID ){223 // objectMap_[objectID ] = *it;223 // if( it->getObjectID()==objectID_ ){ 224 // objectMap_[objectID_] = *it; 224 225 // return *it; 225 226 // } … … 231 232 232 233 /** 233 * This function takes all SynchronisableVariables out of the Synchronisable and saves them together with the size, objectID and classIDto the given memory234 * This function takes all SynchronisableVariables out of the Synchronisable and saves them together with the size, objectID_ and classID_ to the given memory 234 235 * takes a pointer to already allocated memory (must have at least getSize bytes length) 235 236 * structure of the bitstream: 236 * |totalsize,objectID ,classID,var1,var2,string1_length,string1,var3,...|237 * |totalsize,objectID_,classID_,var1,var2,string1_length,string1,var3,...| 237 238 * length of varx: size saved int syncvarlist 238 239 * @param mem pointer to allocated memory with enough size … … 252 253 uint32_t tempsize = 0; 253 254 #ifndef NDEBUG 254 if (this->classID ==0)255 if (this->classID_==0) 255 256 COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl; 256 257 #endif 257 258 258 if (this->classID == static_cast<uint32_t>(-1)) 259 this->classID = this->getIdentifier()->getNetworkID(); 260 261 assert(ClassByID(this->classID)); 262 assert(this->classID==this->getIdentifier()->getNetworkID()); 259 if (this->classID_ == static_cast<uint32_t>(-1)) 260 this->classID_ = this->getIdentifier()->getNetworkID(); 261 262 assert(ClassByID(this->classID_)); 263 assert(this->classID_==this->getIdentifier()->getNetworkID()); 264 assert(this->objectID_!=OBJECTID_UNKNOWN); 263 265 std::vector<SynchronisableVariableBase*>::iterator i; 264 266 … … 269 271 270 272 271 COUT(5) << "Synchronisable getting data from objectID : " << objectID << " classID: " << classID<< std::endl;273 COUT(5) << "Synchronisable getting data from objectID_: " << objectID_ << " classID_: " << classID_ << std::endl; 272 274 // copy to location 273 275 for(i=syncList.begin(); i!=syncList.end(); ++i){ … … 277 279 278 280 tempsize += SynchronisableHeader::getSize(); 279 header.setObjectID( this->objectID );280 header.setCreatorID( this->creatorID );281 header.setClassID( this->classID );281 header.setObjectID( this->objectID_ ); 282 header.setCreatorID( this->creatorID_ ); 283 header.setClassID( this->classID_ ); 282 284 header.setDataAvailable( true ); 283 285 header.setDataSize( tempsize ); … … 311 313 // start extract header 312 314 SynchronisableHeader syncHeader(mem); 313 assert(syncHeader.getObjectID()==this->objectID );314 assert(syncHeader.getCreatorID()==this->creatorID );315 assert(syncHeader.getClassID()==this->classID );315 assert(syncHeader.getObjectID()==this->objectID_); 316 assert(syncHeader.getCreatorID()==this->creatorID_); 317 assert(syncHeader.getClassID()==this->classID_); 316 318 if(syncHeader.isDataAvailable()==false){ 317 319 mem += syncHeader.getDataSize(); … … 322 324 // stop extract header 323 325 324 //COUT(5) << "Synchronisable: objectID " << syncHeader.getObjectID() << ", classID" << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl;326 //COUT(5) << "Synchronisable: objectID_ " << syncHeader.getObjectID() << ", classID_ " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl; 325 327 for(i=syncList.begin(); i!=syncList.end(); i++) 326 328 { … … 361 363 if(mode==0x0) 362 364 mode=state_; 363 return ( ( objectMode_&mode)!=0 && (!syncList.empty() ) );364 } 365 366 /** 367 * This function looks at the header located in the bytestream and checks wheter objectID and classIDmatch with the Synchronisables ones365 return ( (this->objectMode_ & mode)!=0 && (!syncList.empty() ) ); 366 } 367 368 /** 369 * This function looks at the header located in the bytestream and checks wheter objectID_ and classID_ match with the Synchronisables ones 368 370 * @param mem pointer to the bytestream 369 371 */ … … 371 373 { 372 374 SynchronisableHeader header(mem); 373 assert(header.getObjectID()==this->objectID );375 assert(header.getObjectID()==this->objectID_); 374 376 return header.isDataAvailable(); 375 377 } … … 383 385 * @param mode same as in registerVar 384 386 */ 385 void Synchronisable::set ObjectMode(uint8_t mode){387 void Synchronisable::setSyncMode(uint8_t mode){ 386 388 assert(mode==0x0 || mode==0x1 || mode==0x2 || mode==0x3); 387 objectMode_=mode;389 this->objectMode_=mode; 388 390 } 389 391 -
code/trunk/src/libraries/network/synchronisable/Synchronisable.h
r5781 r5929 68 68 * @brief: stores information about a Synchronisable 69 69 * 70 * This class stores the information about a Synchronisable (objectID , classID, creatorID, dataSize)70 * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize) 71 71 * in an emulated bitset. 72 72 * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream 73 73 * Bit 32 is a bool and defines whether the data is actually stored or is just filled up with 0 74 * Byte 5 to 8: objectID 75 * Byte 9 to 12: classID 76 * Byte 13 to 16: creatorID 74 * Byte 5 to 8: objectID_ 75 * Byte 9 to 12: classID_ 76 * Byte 13 to 16: creatorID_ 77 77 */ 78 78 class _NetworkExport SynchronisableHeader{ … … 94 94 inline uint32_t getObjectID() const 95 95 { return *(uint32_t*)(data_+4); } 96 inline void setObjectID(uint32_t objectID )97 { *(uint32_t*)(data_+4) = objectID ; }96 inline void setObjectID(uint32_t objectID_) 97 { *(uint32_t*)(data_+4) = objectID_; } 98 98 inline uint32_t getClassID() const 99 99 { return *(uint32_t*)(data_+8); } 100 inline void setClassID(uint32_t classID )101 { *(uint32_t*)(data_+8) = classID ; }100 inline void setClassID(uint32_t classID_) 101 { *(uint32_t*)(data_+8) = classID_; } 102 102 inline uint32_t getCreatorID() const 103 103 { return *(uint32_t*)(data_+12); } 104 inline void setCreatorID(uint32_t creatorID )105 { *(uint32_t*)(data_+12) = creatorID ; }104 inline void setCreatorID(uint32_t creatorID_) 105 { *(uint32_t*)(data_+12) = creatorID_; } 106 106 inline void operator=(SynchronisableHeader& h) 107 107 { memcpy(data_, h.data_, getSize()); } … … 122 122 123 123 static Synchronisable *fabricate(uint8_t*& mem, uint8_t mode=0x0); 124 static bool deleteObject(uint32_t objectID );125 static Synchronisable *getSynchronisable(uint32_t objectID );124 static bool deleteObject(uint32_t objectID_); 125 static Synchronisable *getSynchronisable(uint32_t objectID_); 126 126 static unsigned int getNumberOfDeletedObject(){ return deletedObjects_.size(); } 127 127 static uint32_t popDeletedObject(){ uint32_t i = deletedObjects_.front(); deletedObjects_.pop(); return i; } 128 128 129 inline uint32_t getObjectID() const {return objectID;} 130 inline unsigned int getCreatorID() const {return creatorID;} 131 inline uint32_t getClassID() const {return classID;} 132 inline unsigned int getPriority() const { return objectFrequency_;} 129 inline uint32_t getObjectID() const {return this->objectID_;} 130 inline unsigned int getCreatorID() const {return this->creatorID_;} 131 inline uint32_t getClassID() const {return this->classID_;} 132 inline unsigned int getPriority() const { return this->objectFrequency_;} 133 inline uint8_t getSyncMode() const { return this->objectMode_; } 134 135 void setSyncMode(uint8_t mode); 133 136 134 137 protected: … … 136 139 template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false); 137 140 //template <class T> void unregisterVariable(T& var); 138 void setObjectMode(uint8_t mode);139 141 void setPriority(unsigned int freq){ objectFrequency_ = freq; } 140 142 … … 146 148 bool isMyData(uint8_t* mem); 147 149 bool doSync(int32_t id, uint8_t mode=0x0); 148 149 uint32_t objectID; 150 uint32_t creatorID; 151 uint32_t classID; 150 151 inline void setObjectID(uint32_t id){ this->objectID_ = id; objectMap_[this->objectID_] = this; } 152 inline void setClassID(uint32_t id){ this->classID_ = id; } 153 154 uint32_t objectID_; 155 uint32_t creatorID_; 156 uint32_t classID_; 152 157 153 158 std::vector<SynchronisableVariableBase*> syncList; -
code/trunk/src/libraries/tools/CMakeLists.txt
r5781 r5929 1 ADD_SOURCE_FILES(TOOLS_SRC_FILES 1 SET_SOURCE_FILES(TOOLS_SRC_FILES 2 COMPILATION_BEGIN ResourceCompilation.cc 3 ResourceCollection.cc 4 ResourceLocation.cc 5 COMPILATION_END 6 TextureGenerator.cc 7 Timer.cc 8 COMPILATION_BEGIN OgreCompilation.cc 2 9 BillboardSet.cc 3 10 DynamicLines.cc … … 5 12 Mesh.cc 6 13 ParticleInterface.cc 7 ResourceCollection.cc8 ResourceLocation.cc9 14 Shader.cc 10 TextureGenerator.cc 11 Timer.cc 15 COMPILATION_END 12 16 ) 13 17 ADD_SUBDIRECTORY(interfaces) … … 15 19 ORXONOX_ADD_LIBRARY(tools 16 20 FIND_HEADER_FILES 17 PCH_FILE18 ToolsPrecompiledHeaders.h19 21 DEFINE_SYMBOL 20 22 "TOOLS_SHARED_BUILD" -
code/trunk/src/libraries/tools/ResourceLocation.cc
r5781 r5929 33 33 34 34 #include "util/Exception.h" 35 #include "core/Core.h"36 35 #include "core/CoreIncludes.h" 36 #include "core/PathConfig.h" 37 37 #include "core/XMLFile.h" 38 38 #include "core/XMLPort.h" … … 71 71 72 72 // Find the path 73 boost::filesystem::path path; 74 if (boost::filesystem::exists(Core::getDataPath() / this->getPath())) 75 path = Core::getDataPath() / this->getPath(); 76 else if (Core::isDevelopmentRun() && boost::filesystem::exists(Core::getExternalDataPath() / this->getPath())) 77 path = Core::getExternalDataPath() / this->getPath(); 73 namespace bf = boost::filesystem; 74 bf::path path; 75 if (bf::exists(PathConfig::getDataPath() / this->getPath())) 76 path = PathConfig::getDataPath() / this->getPath(); 77 else if (PathConfig::isDevelopmentRun() && bf::exists(PathConfig::getExternalDataPath() / this->getPath())) 78 path = PathConfig::getExternalDataPath() / this->getPath(); 78 79 else 79 80 { -
code/trunk/src/libraries/tools/Timer.cc
r5781 r5929 31 31 #include <set> 32 32 33 #include "util/Clock.h" 33 34 #include "core/CoreIncludes.h" 34 35 #include "core/ConsoleCommand.h" 35 36 #include "core/CommandExecutor.h" 36 #include "core/Clock.h"37 37 #include "core/Functor.h" 38 38 … … 42 42 SetConsoleCommandShortcutExtern(killdelays); 43 43 44 static std::set< StaticTimer*> delaytimerset;44 static std::set<Timer*> delaytimerset; 45 45 46 46 /** … … 51 51 void delay(float delay, const std::string& command) 52 52 { 53 StaticTimer *delaytimer = new StaticTimer();53 Timer* delaytimer = new Timer(); 54 54 delaytimerset.insert(delaytimer); 55 55 … … 64 64 @param command The command to execute 65 65 */ 66 void executeDelayedCommand( StaticTimer* timer, const std::string& command)66 void executeDelayedCommand(Timer* timer, const std::string& command) 67 67 { 68 68 CommandExecutor::execute(command); 69 delete timer;69 timer->destroy(); 70 70 delaytimerset.erase(timer); 71 71 } … … 76 76 void killdelays() 77 77 { 78 for (std::set< StaticTimer*>::iterator it = delaytimerset.begin(); it != delaytimerset.end(); ++it)79 delete (*it);78 for (std::set<Timer*>::iterator it = delaytimerset.begin(); it != delaytimerset.end(); ++it) 79 (*it)->destroy(); 80 80 81 81 delaytimerset.clear(); … … 85 85 @brief Constructor: Sets the default-values. 86 86 */ 87 TimerBase::TimerBase() 87 Timer::Timer() 88 { 89 this->init(); 90 RegisterObject(Timer); 91 } 92 93 /** 94 @brief Constructor: Initializes the Timer with given values. 95 @param interval The timer-interval in seconds 96 @param bLoop If true, the function gets called every 'interval' seconds 97 @param exeuctor A executor of the function to call 98 */ 99 Timer::Timer(float interval, bool bLoop, Executor* executor, bool bKillAfterCall) 100 { 101 this->init(); 102 RegisterObject(Timer); 103 104 this->setTimer(interval, bLoop, executor, bKillAfterCall); 105 } 106 107 /** 108 @brief Deletes the executor. 109 */ 110 Timer::~Timer() 111 { 112 this->deleteExecutor(); 113 } 114 115 /** 116 @brief Initializes the Timer 117 */ 118 void Timer::init() 88 119 { 89 120 this->executor_ = 0; … … 94 125 95 126 this->time_ = 0; 96 97 RegisterObject(TimerBase);98 }99 100 /**101 @brief Deletes the executor.102 */103 TimerBase::~TimerBase()104 {105 this->deleteExecutor();106 127 } 107 128 … … 109 130 @brief Executes the executor. 110 131 */ 111 void Timer Base::run() const132 void Timer::run() 112 133 { 113 134 bool temp = this->bKillAfterCall_; // to avoid errors with bKillAfterCall_=false and an exutors which destroy the timer … … 116 137 117 138 if (temp) 118 delete this;139 this->destroy(); 119 140 } 120 141 … … 122 143 @brief Deletes the executor. 123 144 */ 124 void Timer Base::deleteExecutor()145 void Timer::deleteExecutor() 125 146 { 126 147 if (this->executor_) … … 131 152 @brief Updates the timer before the frames are rendered. 132 153 */ 133 void Timer Base::tick(const Clock& time)154 void Timer::tick(const Clock& time) 134 155 { 135 156 if (this->bActive_) -
code/trunk/src/libraries/tools/Timer.h
r5781 r5929 40 40 ClassName(); 41 41 void functionName(); 42 Timer <ClassName>myTimer;42 Timer myTimer; 43 43 }; 44 44 … … 48 48 ClassName::ClassName() 49 49 { 50 myTimer.setTimer(interval_in_seconds, bLoop, this, createExecutor(createFunctor(&ClassName::functionName)));50 myTimer.setTimer(interval_in_seconds, bLoop, createExecutor(createFunctor(&ClassName::functionName, this))); 51 51 } 52 52 … … 69 69 namespace orxonox 70 70 { 71 class StaticTimer;72 71 void delay(float delay, const std::string& command); 73 72 void killdelays(); 74 void executeDelayedCommand( StaticTimer* timer, const std::string& command);73 void executeDelayedCommand(Timer* timer, const std::string& command); 75 74 76 //! T imerBase is the parent of the Timer class.77 class _ToolsExport Timer Base: public TimeFactorListener75 //! The Timer is a callback-object, calling a given function after a given time-interval. 76 class _ToolsExport Timer : public TimeFactorListener 78 77 { 79 78 public: 80 ~TimerBase(); 79 Timer(); 80 ~Timer(); 81 81 82 void run() const; 82 Timer(float interval, bool bLoop, Executor* executor, bool bKillAfterCall = false); 83 84 /** 85 @brief Initializes the Timer with given values. 86 @param interval The timer-interval in seconds 87 @param bLoop If true, the function gets called every 'interval' seconds 88 @param object The object owning the timer and the function 89 @param executor A executor of the function to call 90 */ 91 void setTimer(float interval, bool bLoop, Executor* executor, bool bKillAfterCall = false) 92 { 93 this->deleteExecutor(); 94 95 this->setInterval(interval); 96 this->bLoop_ = bLoop; 97 this->executor_ = executor; 98 this->bActive_ = true; 99 100 this->time_ = this->interval_; 101 this->bKillAfterCall_ = bKillAfterCall; 102 } 103 104 void run(); 83 105 void deleteExecutor(); 84 106 … … 116 138 void tick(const Clock& time); 117 139 118 pr otected:119 TimerBase();120 140 private: 141 void init(); 142 121 143 Executor* executor_; //!< The executor of the function that should be called when the time expires 122 144 … … 128 150 long long time_; //!< Internal variable, counting the time till the next function-call 129 151 }; 130 131 //! The Timer is a callback-object, calling a given function after a given time-interval.132 template <class T = BaseObject>133 class Timer : public TimerBase134 {135 public:136 Timer() {}137 138 /**139 @brief Constructor: Initializes the Timer with given values.140 @param interval The timer-interval in seconds141 @param bLoop If true, the function gets called every 'interval' seconds142 @param object The object owning the timer and the function143 @param exeuctor A executor of the function to call144 */145 Timer(float interval, bool bLoop, T* object, ExecutorMember<T>* exeuctor, bool bKillAfterCall = false)146 {147 this->setTimer(interval, bLoop, object, exeuctor, bKillAfterCall);148 }149 150 /**151 @brief Initializes the Timer with given values.152 @param interval The timer-interval in seconds153 @param bLoop If true, the function gets called every 'interval' seconds154 @param object The object owning the timer and the function155 @param exeuctor A executor of the function to call156 */157 void setTimer(float interval, bool bLoop, T* object, ExecutorMember<T>* executor, bool bKillAfterCall = false)158 {159 this->deleteExecutor();160 161 this->setInterval(interval);162 this->bLoop_ = bLoop;163 executor->setObject(object);164 this->executor_ = static_cast<Executor*>(executor);165 this->bActive_ = true;166 167 this->time_ = this->interval_;168 this->bKillAfterCall_ = bKillAfterCall;169 }170 };171 172 //! The StaticTimer is a callback-object, calling a static function after a given time-interval.173 class _ToolsExport StaticTimer : public TimerBase174 {175 public:176 StaticTimer() {}177 178 /**179 @brief Constructor: Initializes the Timer with given values.180 @param interval The timer-interval in seconds181 @param bLoop If true, the function gets called every 'interval' seconds182 @param exeuctor A executor of the function to call183 */184 StaticTimer(float interval, bool bLoop, ExecutorStatic* executor, bool bKillAfterCall = false)185 {186 this->setTimer(interval, bLoop, executor, bKillAfterCall);187 }188 189 /**190 @brief Initializes the Timer with given values.191 @param interval The timer-interval in seconds192 @param bLoop If true, the function gets called every 'interval' seconds193 @param object The object owning the timer and the function194 @param executor A executor of the function to call195 */196 void setTimer(float interval, bool bLoop, ExecutorStatic* executor, bool bKillAfterCall = false)197 {198 this->deleteExecutor();199 200 this->setInterval(interval);201 this->bLoop_ = bLoop;202 this->executor_ = executor;203 this->bActive_ = true;204 205 this->time_ = this->interval_;206 this->bKillAfterCall_ = bKillAfterCall;207 }208 };209 210 152 } 211 153 -
code/trunk/src/libraries/tools/ToolsPrereqs.h
r5781 r5929 28 28 29 29 /** 30 @file 31 @brief Contains all the necessary forward declarations for all classes and structs. 30 @file 31 @brief 32 Shared library macros, enums, constants and forward declarations for the tools module 32 33 */ 33 34 … … 40 41 // Shared library settings 41 42 //----------------------------------------------------------------------- 43 42 44 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(ORXONOX_STATIC_BUILD) 43 45 # ifdef TOOLS_SHARED_BUILD … … 57 59 58 60 //----------------------------------------------------------------------- 59 // Forward declarations61 // Enums 60 62 //----------------------------------------------------------------------- 61 63 … … 72 74 }; 73 75 } 76 } 74 77 78 //----------------------------------------------------------------------- 79 // Forward declarations 80 //----------------------------------------------------------------------- 81 82 namespace orxonox 83 { 75 84 class BillboardSet; 76 85 class Mesh; 77 86 class ParticleInterface; 87 class ResourceCollection; 88 class ResourceLocation; 78 89 class Shader; 79 template <class T> 90 class Tickable; 91 class TimeFactorListener; 80 92 class Timer; 81 class StaticTimer;82 93 } 83 94 -
code/trunk/src/libraries/util/CMakeLists.txt
r5781 r5929 19 19 20 20 SET_SOURCE_FILES(UTIL_SRC_FILES 21 Clipboard.cc22 CRC32.cc23 21 Exception.cc 24 ExprParser.cc25 22 Math.cc 26 23 MultiType.cc 24 Scope.cc 25 StringUtils.cc 26 COMPILATION_BEGIN StableCompilation.cc 27 Clipboard.cc 28 Clock.cc 29 CRC32.cc 30 ExprParser.cc 27 31 OutputBuffer.cc 28 32 OutputHandler.cc 29 Scope.cc30 33 SignalHandler.cc 31 34 Sleep.cc 32 StringUtils.cc33 35 SubString.cc 36 COMPILATION_END 34 37 ) 35 38 -
code/trunk/src/libraries/util/Scope.h
r5738 r5929 31 31 32 32 #include "UtilPrereqs.h" 33 33 34 #include <cassert> 35 #include <map> 34 36 #include <set> 35 #include <map> 37 36 38 #include "Debug.h" 39 #include "ScopeGuard.h" 37 40 38 41 namespace orxonox 39 42 { 40 namespace ScopeID41 {42 /**43 @brief A list of available scopes for the Scope template.44 */45 enum Value46 {47 GSRoot,48 GSGraphics,49 GSLevel50 };51 }52 53 class ScopeListener; // Forward declaration54 55 43 /** 56 44 @brief The ScopeManager stores the variables of the scope templates in a statically linked context. … … 77 65 protected: 78 66 //! Constructor: Registers the instance. 79 ScopeListener(ScopeID::Value scope) : scope_(scope) 67 ScopeListener(ScopeID::Value scope) : scope_(scope), bActivated_(false) 80 68 { ScopeManager::listeners_s[this->scope_].insert(this); } 81 69 //! Destructor: Unregisters the instance. … … 90 78 private: 91 79 ScopeID::Value scope_; //!< Store the scope to unregister on destruction 80 bool bActivated_; 92 81 }; 93 82 … … 105 94 Scope() 106 95 { 107 ScopeManager::instanceCounts_s[scope]++; 108 assert(ScopeManager::instanceCounts_s[scope] > 0); 109 if (ScopeManager::instanceCounts_s[scope] == 1) 96 try 110 97 { 111 for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); ) 112 (*(it++))->activated(); 98 ScopeManager::instanceCounts_s[scope]++; 99 assert(ScopeManager::instanceCounts_s[scope] > 0); 100 if (ScopeManager::instanceCounts_s[scope] == 1) 101 { 102 Loki::ScopeGuard deactivator = Loki::MakeObjGuard(*this, &Scope::deactivateListeners); 103 for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); ) 104 { 105 (*it)->activated(); 106 (*(it++))->bActivated_ = true; 107 } 108 deactivator.Dismiss(); 109 } 110 } 111 catch (...) 112 { 113 ScopeManager::instanceCounts_s[scope]--; 114 throw; 113 115 } 114 116 } … … 125 127 126 128 if (ScopeManager::instanceCounts_s[scope] == 0) 129 this->deactivateListeners(); 130 } 131 132 void deactivateListeners() 133 { 134 for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); ) 127 135 { 128 for (typename std::set<ScopeListener*>::iterator it = ScopeManager::listeners_s[scope].begin(); it != ScopeManager::listeners_s[scope].end(); ) 129 (*(it++))->deactivated(); 136 if ((*it)->bActivated_) 137 { 138 try 139 { (*it)->deactivated(); } 140 catch (...) 141 { COUT(0) << "ScopeListener::deactivated() failed! This MUST NOT happen, fix it!" << std::endl; } 142 (*(it++))->bActivated_ = false; 143 } 144 else 145 ++it; 130 146 } 131 147 } -
code/trunk/src/libraries/util/Singleton.h
r5738 r5929 55 55 } 56 56 57 //! Update method called by ClassSingletonManager (if used) 58 void updateSingleton(const Clock& time) { static_cast<T*>(T::singletonPtr_s)->update(time); } 59 //! Empty update method for the static polymorphism 60 void update(const Clock& time) { } 61 57 62 protected: 58 63 //! Constructor sets the singleton instance pointer -
code/trunk/src/libraries/util/UtilPrereqs.h
r5738 r5929 28 28 29 29 /** 30 @file 31 @brief Contains all the necessary forward declarations for all classes and structs. 30 @file 31 @brief 32 Shared library macros, enums, constants and forward declarations for the util library 32 33 */ 33 34 … … 40 41 // Shared library settings 41 42 //----------------------------------------------------------------------- 43 42 44 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined( UTIL_STATIC_BUILD ) 43 45 # ifdef UTIL_SHARED_BUILD … … 56 58 #endif 57 59 60 //----------------------------------------------------------------------- 61 // Enums 62 //----------------------------------------------------------------------- 63 64 namespace orxonox 65 { 66 namespace ScopeID 67 { 68 //!A list of available scopes for the Scope template. 69 enum Value 70 { 71 Root, 72 Graphics 73 }; 74 } 75 } 58 76 59 77 //----------------------------------------------------------------------- … … 63 81 namespace orxonox 64 82 { 83 class Clock; 65 84 class Exception; 66 85 class ExprParser; … … 71 90 class OutputBufferListener; 72 91 class OutputHandler; 92 template <ScopeID::Value> 93 class Scope; 94 template <class, ScopeID::Value> 95 class ScopedSingleton; 96 class ScopeListener; 73 97 class SignalHandler; 98 template <class T> 99 class Singleton; 74 100 class SubString; 75 101 }
Note: See TracChangeset
for help on using the changeset viewer.