Changeset 5781 for code/trunk/src/libraries/core
- Timestamp:
- Sep 24, 2009, 11:02:42 AM (15 years ago)
- Location:
- code/trunk/src/libraries/core
- Files:
-
- 17 edited
- 81 copied
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/core/BaseObject.cc
r5774 r5781 33 33 34 34 #include "BaseObject.h" 35 36 #include <tinyxml/tinyxml.h> 37 38 #include "util/StringUtils.h" 35 39 #include "CoreIncludes.h" 40 #include "Event.h" 41 #include "EventIncludes.h" 42 #include "Functor.h" 43 #include "Iterator.h" 44 #include "Template.h" 45 #include "XMLFile.h" 46 #include "XMLNameListener.h" 47 #include "XMLPort.h" 36 48 37 49 namespace orxonox … … 47 59 48 60 this->bInitialized_ = true; 61 62 this->bActive_ = true; 63 this->bVisible_ = true; 64 this->oldGametype_ = 0; 65 66 this->lastLoadedXMLElement_ = 0; 67 68 this->functorSetMainState_ = 0; 69 this->functorGetMainState_ = 0; 70 71 this->setCreator(creator); 72 if (this->creator_) 73 { 74 this->setFile(this->creator_->getFile()); 75 this->setNamespace(this->creator_->getNamespace()); 76 this->setScene(this->creator_->getScene()); 77 this->setGametype(this->creator_->getGametype()); 78 } 79 else 80 { 81 this->file_ = 0; 82 this->namespace_ = 0; 83 this->scene_ = 0; 84 this->gametype_ = 0; 85 } 49 86 } 50 87 … … 56 93 if (this->isInitialized()) 57 94 { 58 } 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_; 105 } 106 } 107 108 /** 109 @brief XML loading and saving. 110 @param xmlelement The XML-element 111 @param loading Loading (true) or saving (false) 112 @return The XML-element 113 */ 114 void BaseObject::XMLPort(Element& xmlelement, XMLPort::Mode mode) 115 { 116 XMLPortParam(BaseObject, "name", setXMLName, getName, xmlelement, mode); 117 XMLPortParam(BaseObject, "visible", setVisible, isVisible, xmlelement, mode); 118 XMLPortParam(BaseObject, "active", setActive, isActive, xmlelement, mode); 119 XMLPortParam(BaseObject, "mainstate", setMainStateName, getMainStateName, xmlelement, mode); 120 121 XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*); 122 123 Element* events = xmlelement.FirstChildElement("events", false); 124 125 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 } 157 } 158 159 /** 160 @brief Loads the name of the object through XML and calls all XMLNameListener. 161 @param name The name of the object 162 */ 163 void BaseObject::setXMLName(const std::string& name) 164 { 165 this->setName(name); 166 167 for (ObjectList<XMLNameListener>::iterator it = ObjectList<XMLNameListener>::begin(); it != ObjectList<XMLNameListener>::end(); ++it) 168 it->loadedNewXMLName(this); 169 } 170 171 /** 172 @brief Returns the levelfile that loaded this object. 173 @return The levelfile 174 */ 175 const std::string& BaseObject::getFilename() const 176 { 177 if (this->file_) 178 return this->file_->getFilename(); 179 else 180 return BLANKSTRING; 181 } 182 183 /** 184 @brief Adds a Template to the object. 185 @param name The name of the Template 186 */ 187 void BaseObject::addTemplate(const std::string& name) 188 { 189 Template* temp = Template::getTemplate(name); 190 if (temp) 191 this->addTemplate(temp); 192 else 193 COUT(1) << "Error: \"" << name << "\" is not a valid Template name (in class: " << this->getIdentifier()->getName() << ", name: " << this->getName() << ")." << std::endl; 194 } 195 196 /** 197 @brief Adds a Template to the object. 198 @param temp The Template 199 */ 200 void BaseObject::addTemplate(Template* temp) 201 { 202 this->templates_.insert(temp); 203 temp->applyOn(this); 204 } 205 206 /** 207 @brief Returns the Template with the given index. 208 @param index The index 209 */ 210 Template* BaseObject::getTemplate(unsigned int index) const 211 { 212 unsigned int i = 0; 213 for (std::set<Template*>::const_iterator it = this->templates_.begin(); it != this->templates_.end(); ++it) 214 { 215 if (i == index) 216 return (*it); 217 i++; 218 } 219 return 0; 220 } 221 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 234 { 235 unsigned int i = 0; 236 for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it) 237 { 238 if (i == index) 239 return (*it); 240 ++i; 241 } 242 return 0; 243 } 244 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; 251 delete (it->second); 252 } 253 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()) 261 return ((*it).second); 262 else 263 return 0; 264 } 265 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 288 void BaseObject::fireEvent(Event& event) 289 { 290 for (std::map<BaseObject*, std::string>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 291 it->first->processEvent(event); 292 } 293 294 void BaseObject::processEvent(Event& event) 295 { 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 315 void BaseObject::setMainState(bool state) 316 { 317 if (this->functorSetMainState_) 318 (*this->functorSetMainState_)(state); 319 else 320 COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl; 321 } 322 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); 59 341 } 60 342 } -
code/trunk/src/libraries/core/BaseObject.h
r5774 r5781 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 39 47 #include "CorePrereqs.h" 48 49 #include <map> 50 #include <list> 51 52 #include "util/mbool.h" 40 53 #include "OrxonoxClass.h" 54 #include "Super.h" 41 55 42 56 namespace orxonox 43 57 { 58 class Scene; 59 class Gametype; 60 44 61 //! The BaseObject is the parent of all classes representing an instance in the game. 45 62 class _CoreExport BaseObject : virtual public OrxonoxClass 46 63 { 64 template <class T> friend class XMLPortClassParamContainer; 65 47 66 public: 48 67 BaseObject(BaseObject* creator); 49 68 virtual ~BaseObject(); 69 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 50 70 51 71 /** @brief Returns if the object was initialized (passed the object registration). @return True was the object is initialized */ 52 72 inline bool isInitialized() const { return this->bInitialized_; } 53 73 74 /** @brief Sets the name of the object. @param name The name */ 75 inline void setName(const std::string& name) { this->oldName_ = this->name_; this->name_ = name; this->changedName(); } 76 /** @brief Returns the name of the object. */ 77 inline const std::string& getName() const { return this->name_; } 78 /** @brief Returns the old name of the object. */ 79 inline const std::string& getOldName() const { return this->oldName_; } 80 /** @brief This function gets called if the name of the object changes. */ 81 virtual void changedName() {} 82 83 /** @brief Sets the state of the objects activity. @param bActive True = active */ 84 inline void setActive(bool bActive) 85 { 86 if (this->bActive_ != bActive) 87 { 88 this->bActive_ = bActive; 89 this->changedActivity(); 90 } 91 } 92 /** @brief Returns the state of the objects activity. @return The state of the activity */ 93 inline const mbool& isActive() const { return this->bActive_; } 94 /** @brief This function gets called if the activity of the object changes. */ 95 virtual void changedActivity() {} 96 97 /** @brief Sets the state of the objects visibility. @param bVisible True = visible */ 98 inline void setVisible(bool bVisible) 99 { 100 if (this->bVisible_ != bVisible) 101 { 102 this->bVisible_ = bVisible; 103 this->changedVisibility(); 104 } 105 } 106 /** @brief Returns the state of the objects visibility. @return The state of the visibility */ 107 inline const mbool& isVisible() const { return this->bVisible_; } 108 /** @brief This function gets called if the visibility of the object changes. */ 109 virtual void changedVisibility() {} 110 111 void setMainState(bool state); 112 bool getMainState() const; 113 114 void setMainStateName(const std::string& name); 115 inline const std::string& getMainStateName() const { return this->mainStateName_; } 116 virtual void changedMainState(); 117 118 /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */ 119 inline void setFile(const XMLFile* file) { this->file_ = file; } 120 /** @brief Returns a pointer to the XMLFile that loaded this object. @return The XMLFile */ 121 inline const XMLFile* getFile() const { return this->file_; } 122 const std::string& getFilename() const; 123 124 void addTemplate(const std::string& name); 125 void addTemplate(Template* temp); 126 /** @brief Returns the set of all aplied templates. */ 127 inline const std::set<Template*>& getTemplates() const 128 { return this->templates_; } 129 130 virtual inline void setNamespace(Namespace* ns) { this->namespace_ = ns; } 131 inline Namespace* getNamespace() const { return this->namespace_; } 132 54 133 inline void setCreator(BaseObject* creator) { this->creator_ = creator; } 55 134 inline BaseObject* getCreator() const { return this->creator_; } 56 135 136 inline void setScene(Scene* scene) { this->scene_ = scene; } 137 inline Scene* getScene() const { return this->scene_; } 138 139 inline void setGametype(Gametype* gametype) 140 { 141 if (gametype != this->gametype_) 142 { 143 this->oldGametype_ = this->gametype_; 144 this->gametype_ = gametype; 145 this->changedGametype(); 146 } 147 } 148 inline Gametype* getGametype() const { return this->gametype_; } 149 inline Gametype* getOldGametype() const { return this->oldGametype_; } 150 virtual void changedGametype() {} 151 152 void fireEvent(); 153 void fireEvent(bool activate); 154 void fireEvent(bool activate, BaseObject* originator); 155 void fireEvent(Event& event); 156 157 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 171 /** @brief Sets the indentation of the debug output in the Loader. @param indentation The indentation */ 172 inline void setLoaderIndentation(const std::string& indentation) { this->loaderIndentation_ = indentation; } 173 /** @brief Returns the indentation of the debug output in the Loader. @return The indentation */ 174 inline const std::string& getLoaderIndentation() const { return this->loaderIndentation_; } 175 176 protected: 177 std::string name_; //!< The name of the object 178 std::string oldName_; //!< The old name of the object 179 mbool bActive_; //!< True = the object is active 180 mbool bVisible_; //!< True = the object is visible 181 std::string mainStateName_; 182 Functor* functorSetMainState_; 183 Functor* functorGetMainState_; 184 57 185 private: 186 void setXMLName(const std::string& name); 187 Template* getTemplate(unsigned int index) const; 188 58 189 bool bInitialized_; //!< True if the object was initialized (passed the object registration) 190 const XMLFile* file_; //!< The XMLFile that loaded this object 191 Element* lastLoadedXMLElement_; //!< Non 0 if the TinyXML attributes have already been copied to our own lowercase map 192 std::map<std::string, std::string> xmlAttributes_; //!< Lowercase XML attributes 193 std::string loaderIndentation_; //!< Indentation of the debug output in the Loader 194 Namespace* namespace_; 59 195 BaseObject* creator_; 196 Scene* scene_; 197 Gametype* gametype_; 198 Gametype* oldGametype_; 199 std::set<Template*> templates_; 200 std::map<BaseObject*, std::string> eventListeners_; 201 std::list<BaseObject*> events_; 202 std::map<std::string, EventContainer*> eventContainers_; 60 203 }; 204 205 SUPER_FUNCTION(0, BaseObject, XMLPort, false); 206 SUPER_FUNCTION(2, BaseObject, changedActivity, false); 207 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); 61 212 } 62 213 -
code/trunk/src/libraries/core/CMakeLists.txt
r5774 r5781 25 25 DynLib.cc 26 26 DynLibManager.cc 27 Event.cc 27 28 Game.cc 29 GameMode.cc 28 30 GameState.cc 31 GraphicsManager.cc 32 GUIManager.cc 29 33 Language.cc 30 34 LuaState.cc 35 MemoryArchive.cc 31 36 ObjectListBase.cc 32 37 OrxonoxClass.cc 38 Resource.cc 39 WindowEventListener.cc 33 40 34 41 # command 42 ArgumentCompletionFunctions.cc 43 CommandEvaluation.cc 44 CommandExecutor.cc 35 45 CommandLine.cc 46 ConsoleCommand.cc 47 ConsoleCommandCompilation.cc 36 48 Executor.cc 37 49 … … 43 55 # level 44 56 BaseObject.cc 57 ClassTreeMask.cc 58 Loader.cc 59 Namespace.cc 60 NamespaceNode.cc 61 Template.cc 62 XMLPort.cc 63 XMLNameListener.cc 45 64 65 # shell 66 IRC.cc 67 Shell.cc 68 TclBind.cc 69 TclThreadManager.cc 70 46 71 # multithreading 47 72 Thread.cc 48 73 ThreadPool.cc 49 74 ) 75 ADD_SUBDIRECTORY(input) 50 76 51 77 ORXONOX_ADD_LIBRARY(core 52 78 FIND_HEADER_FILES 53 79 TOLUA_FILES 80 CommandExecutor.h 81 Loader.h 54 82 LuaState.h 55 83 DEFINE_SYMBOL … … 63 91 ${Boost_THREAD_LIBRARY} 64 92 ${Boost_DATE_TIME_LIBRARY} # Thread dependency 93 ${CEGUI_LIBRARY} 94 ${CEGUILUA_LIBRARY} 65 95 ${LUA_LIBRARIES} 96 cpptcl_orxonox 97 ogreceguirenderer_orxonox 98 ois_orxonox 99 tinyxml++_orxonox 66 100 tolua++_orxonox 67 101 util -
code/trunk/src/libraries/core/ClassFactory.h
r5774 r5781 55 55 { 56 56 public: 57 static bool create(const std::string& name );57 static bool create(const std::string& name, bool bLoadable = true); 58 58 BaseObject* fabricate(BaseObject* creator); 59 59 … … 73 73 */ 74 74 template <class T> 75 bool ClassFactory<T>::create(const std::string& name )75 bool ClassFactory<T>::create(const std::string& name, bool bLoadable) 76 76 { 77 77 COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl; 78 78 ClassIdentifier<T>::getIdentifier(name)->addFactory(new ClassFactory<T>); 79 ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable); 79 80 Factory::add(name, ClassIdentifier<T>::getIdentifier()); 80 81 -
code/trunk/src/libraries/core/Clock.h
r5774 r5781 31 31 32 32 #include "CorePrereqs.h" 33 34 namespace Ogre { class Timer; } 33 #include "util/OgreForwardRefs.h" 35 34 36 35 namespace orxonox -
code/trunk/src/libraries/core/ConfigFileManager.cc
r5774 r5781 34 34 #include "util/Math.h" 35 35 #include "util/StringUtils.h" 36 #include "ConsoleCommand.h" 36 37 #include "ConfigValueContainer.h" 37 38 #include "Core.h" … … 39 40 namespace orxonox 40 41 { 42 SetConsoleCommandShortcutExtern(config).argumentCompleter(0, autocompletion::configvalueclasses()).argumentCompleter(1, autocompletion::configvalues()).argumentCompleter(2, autocompletion::configvalue()); 43 SetConsoleCommandShortcutExtern(tconfig).argumentCompleter(0, autocompletion::configvalueclasses()).argumentCompleter(1, autocompletion::configvalues()).argumentCompleter(2, autocompletion::configvalue()); 44 SetConsoleCommandShortcutExtern(reloadConfig); 45 SetConsoleCommandShortcutExtern(cleanConfig); 46 SetConsoleCommandShortcutExtern(loadSettings).argumentCompleter(0, autocompletion::files()); 47 41 48 bool config(const std::string& classname, const std::string& varname, const std::string& value) 42 49 { -
code/trunk/src/libraries/core/Core.cc
r5774 r5781 63 63 #include "util/SignalHandler.h" 64 64 #include "Clock.h" 65 #include "CommandExecutor.h" 65 66 #include "CommandLine.h" 66 67 #include "ConfigFileManager.h" … … 69 70 #include "DynLibManager.h" 70 71 #include "Factory.h" 72 #include "GameMode.h" 73 #include "GraphicsManager.h" 74 #include "GUIManager.h" 71 75 #include "Identifier.h" 72 76 #include "Language.h" 73 77 #include "LuaState.h" 78 #include "Shell.h" 79 #include "TclBind.h" 80 #include "TclThreadManager.h" 81 #include "input/InputManager.h" 74 82 75 83 // Boost 1.36 has some issues with deprecated functions that have been omitted … … 109 117 RegisterRootObject(CoreConfiguration); 110 118 this->setConfigValues(); 119 120 // External data directory only exists for dev runs 121 if (Core::isDevelopmentRun()) 122 { 123 // Possible data path override by the command line 124 if (!CommandLine::getArgument("externalDataPath")->hasDefaultValue()) 125 tsetExternalDataPath(CommandLine::getValue("externalDataPath")); 126 } 111 127 } 112 128 … … 178 194 } 179 195 196 /** 197 @brief 198 Temporary sets the external data path 199 @param path 200 The new data path 201 */ 202 void tsetExternalDataPath(const std::string& path) 203 { 204 externalDataPath_ = boost::filesystem::path(path); 205 } 206 180 207 void initializeRandomNumberGenerator() 181 208 { … … 201 228 boost::filesystem::path modulePath_; //!< Path to the modules 202 229 boost::filesystem::path dataPath_; //!< Path to the data file folder 230 boost::filesystem::path externalDataPath_; //!< Path to the external data file folder 203 231 boost::filesystem::path configPath_; //!< Path to the config file folder 204 232 boost::filesystem::path logPath_; //!< Path to the log file folder … … 209 237 // Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands) 210 238 : identifierDestroyer_(Identifier::destroyAllIdentifiers) 239 // Cleanup guard for external console commands that don't belong to an Identifier 240 , consoleCommandDestroyer_(CommandExecutor::destroyExternalCommands) 211 241 , configuration_(new CoreConfiguration()) // Don't yet create config values! 212 242 , bDevRun_(false) 243 , bGraphicsLoaded_(false) 213 244 { 214 245 // Set the hard coded fixed paths … … 308 339 // possibility to configure everything below here 309 340 this->configuration_->initialise(); 341 342 // Load OGRE excluding the renderer and the render window 343 this->graphicsManager_.reset(new GraphicsManager(false)); 344 345 // initialise Tcl 346 this->tclBind_.reset(new TclBind(Core::getDataPathString())); 347 this->tclThreadManager_.reset(new TclThreadManager(tclBind_->getTclInterpreter())); 348 349 // create a shell 350 this->shell_.reset(new Shell()); 310 351 } 311 352 … … 316 357 Core::~Core() 317 358 { 359 } 360 361 void Core::loadGraphics() 362 { 363 // Any exception should trigger this, even in upgradeToGraphics (see its remarks) 364 Loki::ScopeGuard unloader = Loki::MakeObjGuard(*this, &Core::unloadGraphics); 365 366 // Upgrade OGRE to receive a render window 367 graphicsManager_->upgradeToGraphics(); 368 369 // Calls the InputManager which sets up the input devices. 370 inputManager_.reset(new InputManager()); 371 372 // load the CEGUI interface 373 guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow(), 374 inputManager_->getMousePosition(), graphicsManager_->isFullScreen())); 375 376 unloader.Dismiss(); 377 378 bGraphicsLoaded_ = true; 379 } 380 381 void Core::unloadGraphics() 382 { 383 this->guiManager_.reset();; 384 this->inputManager_.reset();; 385 this->graphicsManager_.reset(); 386 387 // Load Ogre::Root again, but without the render system 388 try 389 { this->graphicsManager_.reset(new GraphicsManager(false)); } 390 catch (...) 391 { 392 COUT(0) << "An exception occurred during 'unloadGraphics':" << Exception::handleMessage() << std::endl 393 << "Another exception might be being handled which may lead to undefined behaviour!" << std::endl 394 << "Terminating the program." << std::endl; 395 abort(); 396 } 397 398 bGraphicsLoaded_ = false; 318 399 } 319 400 … … 376 457 } 377 458 459 /*static*/ void Core::tsetExternalDataPath(const std::string& path) 460 { 461 getInstance().configuration_->tsetExternalDataPath(path); 462 } 463 378 464 /*static*/ const boost::filesystem::path& Core::getDataPath() 379 465 { … … 383 469 { 384 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() + '/'; 385 480 } 386 481 … … 564 659 { 565 660 configuration_->dataPath_ = specialConfig::dataDevDirectory; 661 configuration_->externalDataPath_ = specialConfig::externalDataDevDirectory; 566 662 configuration_->configPath_ = specialConfig::configDevDirectory; 567 663 configuration_->logPath_ = specialConfig::logDevDirectory; … … 629 725 void Core::preUpdate(const Clock& time) 630 726 { 727 if (this->bGraphicsLoaded_) 728 { 729 // process input events 730 this->inputManager_->update(time); 731 // process gui events 732 this->guiManager_->update(time); 733 } 734 // process thread commands 735 this->tclThreadManager_->update(time); 631 736 } 632 737 633 738 void Core::postUpdate(const Clock& time) 634 739 { 740 if (this->bGraphicsLoaded_) 741 { 742 // Render (doesn't throw) 743 this->graphicsManager_->update(time); 744 } 635 745 } 636 746 } -
code/trunk/src/libraries/core/Core.h
r5774 r5781 85 85 static void resetLanguage(); 86 86 87 static void tsetExternalDataPath(const std::string& path); 87 88 //! Returns the path to the data files as boost::filesystem::path 88 89 static const boost::filesystem::path& getDataPath(); 90 //! Returns the path to the external data files as boost::filesystem::path 91 static const boost::filesystem::path& getExternalDataPath(); 89 92 //! Returns the path to the config files as boost::filesystem::path 90 93 static const boost::filesystem::path& getConfigPath(); … … 95 98 //! Returns the path to the data files as std::string 96 99 static std::string getDataPathString(); 100 //! Returns the path to the external data files as std::string 101 static std::string getExternalDataPathString(); 97 102 //! Returns the path to the config files as std::string 98 103 static std::string getConfigPathString(); … … 110 115 void postUpdate(const Clock& time); 111 116 117 void loadGraphics(); 118 void unloadGraphics(); 119 112 120 void setFixedPaths(); 113 121 void setConfigurablePaths(); … … 118 126 scoped_ptr<SignalHandler> signalHandler_; 119 127 SimpleScopeGuard identifierDestroyer_; 128 SimpleScopeGuard consoleCommandDestroyer_; 120 129 scoped_ptr<ConfigFileManager> configFileManager_; 121 130 scoped_ptr<Language> languageInstance_; 122 131 scoped_ptr<CoreConfiguration> configuration_; 132 scoped_ptr<TclBind> tclBind_; 133 scoped_ptr<TclThreadManager> tclThreadManager_; 134 scoped_ptr<Shell> shell_; 135 // graphical 136 scoped_ptr<GraphicsManager> graphicsManager_; //!< Interface to OGRE 137 scoped_ptr<InputManager> inputManager_; //!< Interface to OIS 138 scoped_ptr<GUIManager> guiManager_; //!< Interface to GUI 123 139 124 140 bool bDevRun_; //!< True for runs in the build directory (not installed) 141 bool bGraphicsLoaded_; 125 142 126 143 static Core* singletonPtr_s; -
code/trunk/src/libraries/core/CoreIncludes.h
r5774 r5781 80 80 */ 81 81 #define CreateFactory(ClassName) \ 82 bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName) 82 bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName, true) 83 84 /** 85 @brief Creates the entry in the Factory for classes which should not be loaded through XML. 86 @param ClassName The name of the class 87 */ 88 #define CreateUnloadableFactory(ClassName) \ 89 bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName, false) 83 90 84 91 /** -
code/trunk/src/libraries/core/CorePrecompiledHeaders.h
r5774 r5781 70 70 #ifdef ORXONOX_COMPILER_MSVC 71 71 72 #include <ois/OISKeyboard.h> // 15 73 #include <ois/OISMouse.h> // 15 74 #include <ois/OISJoyStick.h> // 15 75 72 76 #include "util/SubString.h" // 14 73 77 -
code/trunk/src/libraries/core/Factory.cc
r5774 r5781 55 55 56 56 /** 57 @brief Returns the Identifier with a given network ID. 58 @param id The network ID of the wanted Identifier 59 @return The Identifier 60 */ 61 Identifier* Factory::getIdentifier(const uint32_t id) 62 { 63 std::map<uint32_t, Identifier*>::const_iterator it = getFactoryPointer()->identifierNetworkIDMap_.find(id); 64 if (it != getFactoryPointer()->identifierNetworkIDMap_.end()) 65 return it->second; 66 else 67 return 0; 68 } 69 70 /** 57 71 @brief Adds a new Identifier to both maps. 58 72 @param name The name of the identifier … … 62 76 { 63 77 getFactoryPointer()->identifierStringMap_[name] = identifier; 78 getFactoryPointer()->identifierNetworkIDMap_[identifier->getNetworkID()] = identifier; 79 } 80 81 /** 82 @brief Removes the entry with the old network ID and adds a new one. 83 @param identifier The identifier to change 84 @param oldID The old networkID 85 @param newID The new networkID 86 */ 87 void Factory::changeNetworkID(Identifier* identifier, const uint32_t oldID, const uint32_t newID) 88 { 89 // getFactoryPointer()->identifierNetworkIDMap_.erase(oldID); 90 getFactoryPointer()->identifierNetworkIDMap_[newID] = identifier; 91 } 92 93 /** 94 @brief Cleans the NetworkID map (needed on clients for correct initialization) 95 */ 96 void Factory::cleanNetworkIDs() 97 { 98 getFactoryPointer()->identifierNetworkIDMap_.clear(); 64 99 } 65 100 -
code/trunk/src/libraries/core/Factory.h
r5774 r5781 62 62 static Identifier* getIdentifier(const uint32_t id); 63 63 static void add(const std::string& name, Identifier* identifier); 64 static void changeNetworkID(Identifier* identifier, const uint32_t oldID, const uint32_t newID); 65 static void cleanNetworkIDs(); 64 66 static void createClassHierarchy(); 65 67 … … 82 84 83 85 std::map<std::string, Identifier*> identifierStringMap_; //!< The map, mapping the name with the Identifier 86 std::map<uint32_t, Identifier*> identifierNetworkIDMap_; //!< The map, mapping the network ID with the Identifier 84 87 }; 85 88 -
code/trunk/src/libraries/core/Game.cc
r5774 r5781 45 45 #include "Clock.h" 46 46 #include "CommandLine.h" 47 #include "ConsoleCommand.h" 47 48 #include "Core.h" 48 49 #include "CoreIncludes.h" 49 50 #include "ConfigValueIncludes.h" 51 #include "GameMode.h" 50 52 #include "GameState.h" 51 53 52 54 namespace orxonox 53 55 { 56 static void stop_game() 57 { Game::getInstance().stop(); } 58 SetConsoleCommandShortcutExternAlias(stop_game, "exit"); 59 54 60 std::map<std::string, GameStateInfo> Game::gameStateDeclarations_s; 55 61 Game* Game::singletonPtr_s = 0; … … 500 506 void Game::loadGraphics() 501 507 { 508 if (!GameMode::bShowsGraphics_s) 509 { 510 core_->loadGraphics(); 511 Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics); 512 GameMode::bShowsGraphics_s = true; 513 514 // Construct all the GameStates that require graphics 515 for (std::map<std::string, GameStateInfo>::const_iterator it = gameStateDeclarations_s.begin(); 516 it != gameStateDeclarations_s.end(); ++it) 517 { 518 if (it->second.bGraphicsMode) 519 { 520 // Game state loading failure is serious --> don't catch 521 shared_ptr<GameState> gameState = GameStateFactory::fabricate(it->second); 522 if (!constructedStates_.insert(std::make_pair( 523 it->second.stateName, gameState)).second) 524 assert(false); // GameState was already created! 525 } 526 } 527 graphicsUnloader.Dismiss(); 528 } 502 529 } 503 530 504 531 void Game::unloadGraphics() 505 532 { 533 if (GameMode::bShowsGraphics_s) 534 { 535 // Destroy all the GameStates that require graphics 536 for (GameStateMap::iterator it = constructedStates_.begin(); it != constructedStates_.end();) 537 { 538 if (it->second->getInfo().bGraphicsMode) 539 constructedStates_.erase(it++); 540 else 541 ++it; 542 } 543 544 core_->unloadGraphics(); 545 GameMode::bShowsGraphics_s = false; 546 } 506 547 } 507 548 … … 522 563 // If state requires graphics, load it 523 564 Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics); 524 if (gameStateDeclarations_s[name].bGraphicsMode )565 if (gameStateDeclarations_s[name].bGraphicsMode && !GameMode::showsGraphics()) 525 566 this->loadGraphics(); 526 567 else -
code/trunk/src/libraries/core/Identifier.cc
r5774 r5781 38 38 #include "util/StringUtils.h" 39 39 #include "ConfigValueContainer.h" 40 #include "ConsoleCommand.h" 40 41 #include "Factory.h" 42 #include "XMLPort.h" 41 43 42 44 namespace orxonox … … 59 61 this->bSetName_ = false; 60 62 this->factory_ = 0; 63 this->bLoadable_ = true; 61 64 62 65 this->bHasConfigValues_ = false; 66 this->bHasConsoleCommands_ = false; 63 67 64 68 this->children_ = new std::set<const Identifier*>(); 65 69 this->directChildren_ = new std::set<const Identifier*>(); 70 71 // Default network ID is the class ID 72 this->networkID_ = this->classID_; 66 73 } 67 74 … … 78 85 delete this->factory_; 79 86 87 for (std::map<std::string, ConsoleCommand*>::iterator it = this->consoleCommands_.begin(); it != this->consoleCommands_.end(); ++it) 88 delete (it->second); 80 89 for (std::map<std::string, ConfigValueContainer*>::iterator it = this->configValues_.begin(); it != this->configValues_.end(); ++it) 90 delete (it->second); 91 for (std::map<std::string, XMLPortParamContainer*>::iterator it = this->xmlportParamContainers_.begin(); it != this->xmlportParamContainers_.end(); ++it) 92 delete (it->second); 93 for (std::map<std::string, XMLPortObjectContainer*>::iterator it = this->xmlportObjectContainers_.begin(); it != this->xmlportObjectContainers_.end(); ++it) 81 94 delete (it->second); 82 95 } … … 175 188 // Tell the parent we're one of it's direct children 176 189 (*it)->getDirectChildrenIntern().insert((*it)->getDirectChildrenIntern().end(), this); 190 191 // Create the super-function dependencies 192 (*it)->createSuperFunctionCaller(); 177 193 } 178 194 } … … 224 240 225 241 /** 242 @brief Sets the network ID to a new value and changes the entry in the Factory. 243 @param id The new network ID 244 */ 245 void Identifier::setNetworkID(uint32_t id) 246 { 247 Factory::changeNetworkID(this, this->networkID_, id); 248 this->networkID_ = id; 249 } 250 251 /** 226 252 @brief Returns true, if the Identifier is at least of the given type. 227 253 @param identifier The identifier to compare with … … 342 368 else 343 369 return 0; 370 } 371 372 /** 373 @brief Adds a new console command of this class. 374 @param executor The executor of the command 375 @param bCreateShortcut If this is true a shortcut gets created so you don't have to add the classname to access this command 376 @return The executor of the command 377 */ 378 ConsoleCommand& Identifier::addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut) 379 { 380 std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(command->getName()); 381 if (it != this->consoleCommands_.end()) 382 { 383 COUT(2) << "Warning: Overwriting console-command with name " << command->getName() << " in class " << this->getName() << "." << std::endl; 384 delete (it->second); 385 } 386 387 this->bHasConsoleCommands_ = true; 388 this->consoleCommands_[command->getName()] = command; 389 this->consoleCommands_LC_[getLowercase(command->getName())] = command; 390 391 if (bCreateShortcut) 392 CommandExecutor::addConsoleCommandShortcut(command); 393 394 return (*command); 395 } 396 397 /** 398 @brief Returns the executor of a console command with given name. 399 @brief name The name of the requested console command 400 @return The executor of the requested console command 401 */ 402 ConsoleCommand* Identifier::getConsoleCommand(const std::string& name) const 403 { 404 std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(name); 405 if (it != this->consoleCommands_.end()) 406 return (*it).second; 407 else 408 return 0; 409 } 410 411 /** 412 @brief Returns the executor of a console command with given name in lowercase. 413 @brief name The name of the requested console command in lowercae 414 @return The executor of the requested console command 415 */ 416 ConsoleCommand* Identifier::getLowercaseConsoleCommand(const std::string& name) const 417 { 418 std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_LC_.find(name); 419 if (it != this->consoleCommands_LC_.end()) 420 return (*it).second; 421 else 422 return 0; 423 } 424 425 /** 426 @brief Returns a XMLPortParamContainer that loads a parameter of this class. 427 @param paramname The name of the parameter 428 @return The container 429 */ 430 XMLPortParamContainer* Identifier::getXMLPortParamContainer(const std::string& paramname) 431 { 432 std::map<std::string, XMLPortParamContainer*>::const_iterator it = this->xmlportParamContainers_.find(paramname); 433 if (it != this->xmlportParamContainers_.end()) 434 return ((*it).second); 435 else 436 return 0; 437 } 438 439 /** 440 @brief Adds a new XMLPortParamContainer that loads a parameter of this class. 441 @param paramname The name of the parameter 442 @param container The container 443 */ 444 void Identifier::addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container) 445 { 446 std::map<std::string, XMLPortParamContainer*>::const_iterator it = this->xmlportParamContainers_.find(paramname); 447 if (it != this->xmlportParamContainers_.end()) 448 { 449 COUT(2) << "Warning: Overwriting XMLPortParamContainer in class " << this->getName() << "." << std::endl; 450 delete (it->second); 451 } 452 453 this->xmlportParamContainers_[paramname] = container; 454 } 455 456 /** 457 @brief Returns a XMLPortObjectContainer that attaches an object to this class. 458 @param sectionname The name of the section that contains the attachable objects 459 @return The container 460 */ 461 XMLPortObjectContainer* Identifier::getXMLPortObjectContainer(const std::string& sectionname) 462 { 463 std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportObjectContainers_.find(sectionname); 464 if (it != this->xmlportObjectContainers_.end()) 465 return ((*it).second); 466 else 467 return 0; 468 } 469 470 /** 471 @brief Adds a new XMLPortObjectContainer that attaches an object to this class. 472 @param sectionname The name of the section that contains the attachable objects 473 @param container The container 474 */ 475 void Identifier::addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container) 476 { 477 std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportObjectContainers_.find(sectionname); 478 if (it != this->xmlportObjectContainers_.end()) 479 { 480 COUT(2) << "Warning: Overwriting XMLPortObjectContainer in class " << this->getName() << "." << std::endl; 481 delete (it->second); 482 } 483 484 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 event 490 @return The container 491 */ 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 else 498 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 event 504 @param container The container 505 */ 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; 344 516 } 345 517 -
code/trunk/src/libraries/core/Identifier.h
r5774 r5781 66 66 #include "ObjectList.h" 67 67 #include "ObjectListBase.h" 68 #include "Super.h" 68 69 69 70 namespace orxonox … … 106 107 bool isDirectParentOf(const Identifier* identifier) const; 107 108 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 108 114 /** @brief Returns the list of all existing objects of this class. @return The list */ 109 115 inline ObjectListBase* getObjects() const … … 175 181 176 182 183 /** @brief Returns the map that stores all console commands. @return The const_iterator */ 184 inline const std::map<std::string, ConsoleCommand*>& getConsoleCommandMap() const { return this->consoleCommands_; } 185 /** @brief Returns a const_iterator to the beginning of the map that stores all console commands. @return The const_iterator */ 186 inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandMapBegin() const { return this->consoleCommands_.begin(); } 187 /** @brief Returns a const_iterator to the end of the map that stores all console commands. @return The const_iterator */ 188 inline std::map<std::string, ConsoleCommand*>::const_iterator getConsoleCommandMapEnd() const { return this->consoleCommands_.end(); } 189 190 /** @brief Returns the map that stores all console commands with their names in lowercase. @return The const_iterator */ 191 inline const std::map<std::string, ConsoleCommand*>& getLowercaseConsoleCommandMap() const { return this->consoleCommands_LC_; } 192 /** @brief Returns a const_iterator to the beginning of the map that stores all console commands with their names in lowercase. @return The const_iterator */ 193 inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandMapBegin() const { return this->consoleCommands_LC_.begin(); } 194 /** @brief Returns a const_iterator to the end of the map that stores all console commands with their names in lowercase. @return The const_iterator */ 195 inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandMapEnd() const { return this->consoleCommands_LC_.end(); } 196 197 /** @brief Returns the map that stores all XMLPort params. @return The const_iterator */ 198 inline const std::map<std::string, XMLPortParamContainer*>& getXMLPortParamMap() const { return this->xmlportParamContainers_; } 199 /** @brief Returns a const_iterator to the beginning of the map that stores all XMLPort params. @return The const_iterator */ 200 inline std::map<std::string, XMLPortParamContainer*>::const_iterator getXMLPortParamMapBegin() const { return this->xmlportParamContainers_.begin(); } 201 /** @brief Returns a const_iterator to the end of the map that stores all XMLPort params. @return The const_iterator */ 202 inline std::map<std::string, XMLPortParamContainer*>::const_iterator getXMLPortParamMapEnd() const { return this->xmlportParamContainers_.end(); } 203 204 /** @brief Returns the map that stores all XMLPort objects. @return The const_iterator */ 205 inline const std::map<std::string, XMLPortObjectContainer*>& getXMLPortObjectMap() const { return this->xmlportObjectContainers_; } 206 /** @brief Returns a const_iterator to the beginning of the map that stores all XMLPort objects. @return The const_iterator */ 207 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapBegin() const { return this->xmlportObjectContainers_.begin(); } 208 /** @brief Returns a const_iterator to the end of the map that stores all XMLPort objects. @return The const_iterator */ 209 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapEnd() const { return this->xmlportObjectContainers_.end(); } 210 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 177 218 /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */ 178 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_; } 179 222 180 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 */ 181 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); 182 231 183 232 /** @brief Returns the unique ID of the class */ … … 187 236 ConfigValueContainer* getConfigValueContainer(const std::string& varname); 188 237 ConfigValueContainer* getLowercaseConfigValueContainer(const std::string& varname); 238 239 void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container); 240 XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname); 241 242 void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container); 243 XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname); 244 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; 189 251 190 252 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass); … … 198 260 199 261 static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal); 262 virtual void createSuperFunctionCaller() const = 0; 200 263 201 264 /** @brief Returns the map that stores all Identifiers. @return The map */ … … 242 305 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) 243 306 bool bSetName_; //!< True if the name is set 307 bool bLoadable_; //!< False = it's not permitted to load the object through XML 244 308 std::string name_; //!< The name of the class the Identifier belongs to 245 309 BaseFactory* factory_; //!< The Factory, able to create new objects of the given class (if available) 246 310 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 uint32_t networkID_; //!< The network ID to identify a class through the network 247 312 const unsigned int classID_; //!< Uniquely identifies a class (might not be the same as the networkID_) 248 313 static unsigned int classIDCounter_s; //!< Static counter for the unique classIDs … … 251 316 std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer 252 317 std::map<std::string, ConfigValueContainer*> configValues_LC_; //!< A map to link the string of configurable variables with their ConfigValueContainer 318 319 bool bHasConsoleCommands_; //!< True if this class has at least one assigned console command 320 std::map<std::string, ConsoleCommand*> consoleCommands_; //!< All console commands of this class 321 std::map<std::string, ConsoleCommand*> consoleCommands_LC_; //!< All console commands of this class with their names in lowercase 322 323 std::map<std::string, XMLPortParamContainer*> xmlportParamContainers_; //!< All loadable parameters 324 std::map<std::string, XMLPortObjectContainer*> xmlportObjectContainers_; //!< All attachable objects 325 std::map<std::string, XMLPortObjectContainer*> xmlportEventContainers_; //!< All events 253 326 }; 254 327 … … 271 344 class ClassIdentifier : public Identifier 272 345 { 346 #define SUPER_INTRUSIVE_DECLARATION_INCLUDE 347 #include "Super.h" 348 273 349 public: 274 350 static ClassIdentifier<T> *getIdentifier(); … … 284 360 ClassIdentifier() 285 361 { 362 SuperFunctionInitialization<0, T>::initialize(this); 286 363 } 287 364 ~ClassIdentifier() 288 365 { 366 SuperFunctionDestruction<0, T>::destroy(this); 289 367 } 290 368 … … 552 630 { return this->identifier_; } 553 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) const 634 // { 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) const 638 // { 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) const 642 // { 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) const 646 // { 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) const 650 // { 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) const 654 // { return this->identifier_->isDirectParentOf(identifier); } 655 554 656 private: 555 657 Identifier* identifier_; //!< The assigned identifier -
code/trunk/src/libraries/core/LuaState.cc
r5774 r5781 30 30 #include "LuaState.h" 31 31 32 #include <boost/filesystem.hpp>33 32 #include <tolua/tolua++.h> 34 33 extern "C" { … … 39 38 #include "util/Debug.h" 40 39 #include "Core.h" 40 #include "Resource.h" 41 41 #include "ToluaBindCore.h" 42 42 … … 71 71 // Create dummy file info 72 72 sourceFileInfo_.reset(new ResourceInfo()); 73 sourceFileInfo_->group = "General"; 74 sourceFileInfo_->size = 0; 73 75 74 76 // Push 'this' pointer … … 85 87 } 86 88 87 shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename, bool bSearchOtherPaths)89 shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths) 88 90 { 89 91 shared_ptr<ResourceInfo> sourceInfo; 90 sourceInfo = this->getFileInfo(filename); 92 if (resourceGroup != "NoResourceGroupProvided") 93 sourceInfo = Resource::getInfo(filename, resourceGroup); 91 94 92 95 // Continue search if not explicitely forbidden … … 94 97 { 95 98 // Call might be relative to the file currently being processed 96 sourceInfo = this->getFileInfo(sourceFileInfo_->path + filename);99 sourceInfo = Resource::getInfo(sourceFileInfo_->path + filename, sourceFileInfo_->group); 97 100 if (sourceInfo == NULL) 98 101 { 99 102 // Maybe find something in the same group but in the root path 100 sourceInfo = this->getFileInfo(filename);103 sourceInfo = Resource::getInfo(filename, sourceFileInfo_->group); 101 104 } 102 105 } … … 104 107 } 105 108 106 shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename) 107 { 108 boost::filesystem::path filepath = Core::getDataPath() / "lua" / filename; 109 if (boost::filesystem::exists(filepath)) 110 { 111 shared_ptr<ResourceInfo> info(new ResourceInfo()); 112 info->filename = filepath.string(); 113 info->path = filepath.branch_path().string(); 114 info->basename = filepath.leaf(); 115 return info; 116 } 117 else 118 return shared_ptr<ResourceInfo>(); 119 } 120 121 std::string LuaState::loadFile(const std::string& filename) 122 { 123 std::ifstream file(filename.c_str()); 124 std::ostringstream oss; 125 oss << file.rdbuf(); 126 return oss.str(); 127 } 128 129 void LuaState::includeFile(const std::string& filename, bool bSearchOtherPaths) 130 { 131 shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, bSearchOtherPaths); 109 void LuaState::includeFile(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths) 110 { 111 shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, resourceGroup, bSearchOtherPaths); 132 112 if (sourceInfo != NULL) 133 this->includeString(this->loadFile(sourceInfo->filename), sourceInfo); 134 else 135 COUT(2) << "LuaState: Cannot include file '" << filename << std::endl; 113 this->includeString(Resource::open(sourceInfo->filename, sourceInfo->group)->getAsString(), sourceInfo); 114 else 115 COUT(2) << "LuaState: Cannot include file '" << filename << "' in resource group '" 116 << (resourceGroup == "NoResourceGroupProvided" ? sourceFileInfo_->group : resourceGroup) << "': group not found." << std::endl; 136 117 } 137 118 … … 148 129 } 149 130 150 void LuaState::doFile(const std::string& filename, bool bSearchOtherPaths)151 { 152 shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, bSearchOtherPaths);131 void LuaState::doFile(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths) 132 { 133 shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, resourceGroup, bSearchOtherPaths); 153 134 if (sourceInfo != NULL) 154 this->doString(this->loadFile(sourceInfo->filename), sourceInfo); 155 else 156 COUT(2) << "LuaState: Cannot do file '" << filename << std::endl; 135 this->doString(Resource::open(sourceInfo->filename, sourceInfo->group)->getAsString(), sourceInfo); 136 else 137 COUT(2) << "LuaState: Cannot do file '" << filename << "' in resource group '" 138 << (resourceGroup == "NoResourceGroupProvided" ? sourceFileInfo_->group : resourceGroup) << "': group not found." << std::endl; 157 139 } 158 140 … … 204 186 } 205 187 206 bool LuaState::fileExists(const std::string& filename, bool bSearchOtherPaths)207 { 208 shared_ptr<ResourceInfo> info = this->getFileInfo(filename, bSearchOtherPaths);188 bool LuaState::fileExists(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths) 189 { 190 shared_ptr<ResourceInfo> info = this->getFileInfo(filename, resourceGroup, bSearchOtherPaths); 209 191 if (info == NULL) 210 192 return false; -
code/trunk/src/libraries/core/LuaState.h
r5774 r5781 45 45 namespace orxonox 46 46 { 47 //! Stores basic information about a File48 struct ResourceInfo49 {50 //! The file's fully qualified name51 std::string filename;52 //! Path name; separated by '/' and ending with '/'53 std::string path;54 //! Base filename55 std::string basename;56 };57 58 47 /** 59 48 @brief … … 67 56 ~LuaState(); 68 57 69 void doFile(const std::string& filename, bool bSearchOtherPaths = true); // tolua_export58 void doFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export 70 59 void doString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>()); 71 60 72 void includeFile(const std::string& filename, bool bSearchOtherPaths = true); // tolua_export61 void includeFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export 73 62 void includeString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>()); 74 63 75 64 void luaPrint(const std::string& str); // tolua_export 76 65 void luaLog(unsigned int level, const std::string& message); // tolua_export 77 bool fileExists(const std::string& filename, bool bSearchOtherPaths = true); // tolua_export66 bool fileExists(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export 78 67 79 68 const std::stringstream& getOutput() const { return output_; } … … 89 78 90 79 private: 91 shared_ptr<ResourceInfo> getFileInfo(const std::string& filename, bool bSearchOtherPaths); 92 shared_ptr<ResourceInfo> getFileInfo(const std::string& filename); 93 std::string loadFile(const std::string& filename); 80 shared_ptr<ResourceInfo> getFileInfo(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths); 94 81 95 82 #if LUA_VERSION_NUM != 501
Note: See TracChangeset
for help on using the changeset viewer.