Changeset 5774 for code/trunk/src/libraries
- Timestamp:
- Sep 23, 2009, 11:31:02 PM (15 years ago)
- Location:
- code/trunk/src/libraries
- Files:
-
- 59 deleted
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/CMakeLists.txt
r5752 r5774 26 26 27 27 ADD_SUBDIRECTORY(core) 28 ADD_SUBDIRECTORY(network)29 ADD_SUBDIRECTORY(tools)30 28 ADD_SUBDIRECTORY(util) -
code/trunk/src/libraries/core/BaseObject.cc
r5738 r5774 33 33 34 34 #include "BaseObject.h" 35 36 #include <tinyxml/tinyxml.h>37 38 #include "util/StringUtils.h"39 35 #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"48 36 49 37 namespace orxonox … … 59 47 60 48 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 else80 {81 this->file_ = 0;82 this->namespace_ = 0;83 this->scene_ = 0;84 this->gametype_ = 0;85 }86 49 } 87 50 … … 93 56 if (this->isInitialized()) 94 57 { 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 58 } 106 59 } 107 108 /**109 @brief XML loading and saving.110 @param xmlelement The XML-element111 @param loading Loading (true) or saving (false)112 @return The XML-element113 */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 object162 */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 levelfile174 */175 const std::string& BaseObject::getFilename() const176 {177 if (this->file_)178 return this->file_->getFilename();179 else180 return BLANKSTRING;181 }182 183 /**184 @brief Adds a Template to the object.185 @param name The name of the Template186 */187 void BaseObject::addTemplate(const std::string& name)188 {189 Template* temp = Template::getTemplate(name);190 if (temp)191 this->addTemplate(temp);192 else193 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 Template199 */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 index209 */210 Template* BaseObject::getTemplate(unsigned int index) const211 {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) const234 {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) const258 {259 std::map<std::string, EventContainer*>::const_iterator it = this->eventContainers_.find(sectionname);260 if (it != this->eventContainers_.end())261 return ((*it).second);262 else263 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 else320 COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl;321 }322 323 bool BaseObject::getMainState() const324 {325 if (this->functorGetMainState_)326 {327 (*this->functorGetMainState_)();328 return this->functorGetMainState_->getReturnvalue();329 }330 else331 {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);341 }342 60 } -
code/trunk/src/libraries/core/BaseObject.h
r5738 r5774 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 49 #include <map>50 #include <list>51 52 #include "util/mbool.h"53 40 #include "OrxonoxClass.h" 54 #include "Super.h"55 41 56 42 namespace orxonox 57 43 { 58 class Scene;59 class Gametype;60 61 44 //! The BaseObject is the parent of all classes representing an instance in the game. 62 45 class _CoreExport BaseObject : virtual public OrxonoxClass 63 46 { 64 template <class T> friend class XMLPortClassParamContainer;65 66 47 public: 67 48 BaseObject(BaseObject* creator); 68 49 virtual ~BaseObject(); 69 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);70 50 71 51 /** @brief Returns if the object was initialized (passed the object registration). @return True was the object is initialized */ 72 52 inline bool isInitialized() const { return this->bInitialized_; } 73 53 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() const128 { return this->templates_; }129 130 virtual inline void setNamespace(Namespace* ns) { this->namespace_ = ns; }131 inline Namespace* getNamespace() const { return this->namespace_; }132 133 54 inline void setCreator(BaseObject* creator) { this->creator_ = creator; } 134 55 inline BaseObject* getCreator() const { return this->creator_; } 135 56 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 object178 std::string oldName_; //!< The old name of the object179 mbool bActive_; //!< True = the object is active180 mbool bVisible_; //!< True = the object is visible181 std::string mainStateName_;182 Functor* functorSetMainState_;183 Functor* functorGetMainState_;184 185 57 private: 186 void setXMLName(const std::string& name);187 Template* getTemplate(unsigned int index) const;188 189 58 bool bInitialized_; //!< True if the object was initialized (passed the object registration) 190 const XMLFile* file_; //!< The XMLFile that loaded this object191 Element* lastLoadedXMLElement_; //!< Non 0 if the TinyXML attributes have already been copied to our own lowercase map192 std::map<std::string, std::string> xmlAttributes_; //!< Lowercase XML attributes193 std::string loaderIndentation_; //!< Indentation of the debug output in the Loader194 Namespace* namespace_;195 59 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_;203 60 }; 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);212 61 } 213 62 -
code/trunk/src/libraries/core/CMakeLists.txt
r5738 r5774 25 25 DynLib.cc 26 26 DynLibManager.cc 27 Event.cc28 27 Game.cc 29 GameMode.cc30 28 GameState.cc 31 GraphicsManager.cc32 GUIManager.cc33 29 Language.cc 34 30 LuaState.cc 35 MemoryArchive.cc36 31 ObjectListBase.cc 37 32 OrxonoxClass.cc 38 Resource.cc39 WindowEventListener.cc40 33 41 34 # command 42 ArgumentCompletionFunctions.cc43 CommandEvaluation.cc44 CommandExecutor.cc45 35 CommandLine.cc 46 ConsoleCommand.cc47 ConsoleCommandCompilation.cc48 36 Executor.cc 49 37 … … 55 43 # level 56 44 BaseObject.cc 57 ClassTreeMask.cc58 Loader.cc59 Namespace.cc60 NamespaceNode.cc61 Template.cc62 XMLPort.cc63 XMLNameListener.cc64 45 65 # shell66 IRC.cc67 Shell.cc68 TclBind.cc69 TclThreadManager.cc70 71 46 # multithreading 72 47 Thread.cc 73 48 ThreadPool.cc 74 49 ) 75 ADD_SUBDIRECTORY(input)76 50 77 51 ORXONOX_ADD_LIBRARY(core 78 52 FIND_HEADER_FILES 79 53 TOLUA_FILES 80 CommandExecutor.h81 Loader.h82 54 LuaState.h 83 55 DEFINE_SYMBOL … … 91 63 ${Boost_THREAD_LIBRARY} 92 64 ${Boost_DATE_TIME_LIBRARY} # Thread dependency 93 ${CEGUI_LIBRARY}94 ${CEGUILUA_LIBRARY}95 65 ${LUA_LIBRARIES} 96 cpptcl_orxonox97 ogreceguirenderer_orxonox98 ois_orxonox99 tinyxml++_orxonox100 66 tolua++_orxonox 101 67 util -
code/trunk/src/libraries/core/ClassFactory.h
r5738 r5774 55 55 { 56 56 public: 57 static bool create(const std::string& name , bool bLoadable = true);57 static bool create(const std::string& name); 58 58 BaseObject* fabricate(BaseObject* creator); 59 59 … … 73 73 */ 74 74 template <class T> 75 bool ClassFactory<T>::create(const std::string& name , bool bLoadable)75 bool ClassFactory<T>::create(const std::string& name) 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);80 79 Factory::add(name, ClassIdentifier<T>::getIdentifier()); 81 80 -
code/trunk/src/libraries/core/Clock.h
r5738 r5774 31 31 32 32 #include "CorePrereqs.h" 33 #include "util/OgreForwardRefs.h" 33 34 namespace Ogre { class Timer; } 34 35 35 36 namespace orxonox -
code/trunk/src/libraries/core/ConfigFileManager.cc
r5738 r5774 34 34 #include "util/Math.h" 35 35 #include "util/StringUtils.h" 36 #include "ConsoleCommand.h"37 36 #include "ConfigValueContainer.h" 38 37 #include "Core.h" … … 40 39 namespace orxonox 41 40 { 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 48 41 bool config(const std::string& classname, const std::string& varname, const std::string& value) 49 42 { -
code/trunk/src/libraries/core/Core.cc
r5759 r5774 63 63 #include "util/SignalHandler.h" 64 64 #include "Clock.h" 65 #include "CommandExecutor.h"66 65 #include "CommandLine.h" 67 66 #include "ConfigFileManager.h" … … 70 69 #include "DynLibManager.h" 71 70 #include "Factory.h" 72 #include "GameMode.h"73 #include "GraphicsManager.h"74 #include "GUIManager.h"75 71 #include "Identifier.h" 76 72 #include "Language.h" 77 73 #include "LuaState.h" 78 #include "Shell.h"79 #include "TclBind.h"80 #include "TclThreadManager.h"81 #include "input/InputManager.h"82 74 83 75 // Boost 1.36 has some issues with deprecated functions that have been omitted … … 117 109 RegisterRootObject(CoreConfiguration); 118 110 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 111 } 128 112 … … 194 178 } 195 179 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 180 void initializeRandomNumberGenerator() 208 181 { … … 228 201 boost::filesystem::path modulePath_; //!< Path to the modules 229 202 boost::filesystem::path dataPath_; //!< Path to the data file folder 230 boost::filesystem::path externalDataPath_; //!< Path to the external data file folder231 203 boost::filesystem::path configPath_; //!< Path to the config file folder 232 204 boost::filesystem::path logPath_; //!< Path to the log file folder … … 237 209 // Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands) 238 210 : identifierDestroyer_(Identifier::destroyAllIdentifiers) 239 // Cleanup guard for external console commands that don't belong to an Identifier240 , consoleCommandDestroyer_(CommandExecutor::destroyExternalCommands)241 211 , configuration_(new CoreConfiguration()) // Don't yet create config values! 242 212 , bDevRun_(false) 243 , bGraphicsLoaded_(false)244 213 { 245 214 // Set the hard coded fixed paths … … 339 308 // possibility to configure everything below here 340 309 this->configuration_->initialise(); 341 342 // Load OGRE excluding the renderer and the render window343 this->graphicsManager_.reset(new GraphicsManager(false));344 345 // initialise Tcl346 this->tclBind_.reset(new TclBind(Core::getDataPathString()));347 this->tclThreadManager_.reset(new TclThreadManager(tclBind_->getTclInterpreter()));348 349 // create a shell350 this->shell_.reset(new Shell());351 310 } 352 311 … … 357 316 Core::~Core() 358 317 { 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 window367 graphicsManager_->upgradeToGraphics();368 369 // Calls the InputManager which sets up the input devices.370 inputManager_.reset(new InputManager());371 372 // load the CEGUI interface373 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 system388 try389 { this->graphicsManager_.reset(new GraphicsManager(false)); }390 catch (...)391 {392 COUT(0) << "An exception occurred during 'unloadGraphics':" << Exception::handleMessage() << std::endl393 << "Another exception might be being handled which may lead to undefined behaviour!" << std::endl394 << "Terminating the program." << std::endl;395 abort();396 }397 398 bGraphicsLoaded_ = false;399 318 } 400 319 … … 457 376 } 458 377 459 /*static*/ void Core::tsetExternalDataPath(const std::string& path)460 {461 getInstance().configuration_->tsetExternalDataPath(path);462 }463 464 378 /*static*/ const boost::filesystem::path& Core::getDataPath() 465 379 { … … 469 383 { 470 384 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 385 } 481 386 … … 659 564 { 660 565 configuration_->dataPath_ = specialConfig::dataDevDirectory; 661 configuration_->externalDataPath_ = specialConfig::externalDataDevDirectory;662 566 configuration_->configPath_ = specialConfig::configDevDirectory; 663 567 configuration_->logPath_ = specialConfig::logDevDirectory; … … 725 629 void Core::preUpdate(const Clock& time) 726 630 { 727 if (this->bGraphicsLoaded_)728 {729 // process input events730 this->inputManager_->update(time);731 // process gui events732 this->guiManager_->update(time);733 }734 // process thread commands735 this->tclThreadManager_->update(time);736 631 } 737 632 738 633 void Core::postUpdate(const Clock& time) 739 634 { 740 if (this->bGraphicsLoaded_)741 {742 // Render (doesn't throw)743 this->graphicsManager_->update(time);744 }745 635 } 746 636 } -
code/trunk/src/libraries/core/Core.h
r5738 r5774 85 85 static void resetLanguage(); 86 86 87 static void tsetExternalDataPath(const std::string& path);88 87 //! Returns the path to the data files as boost::filesystem::path 89 88 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 89 //! Returns the path to the config files as boost::filesystem::path 93 90 static const boost::filesystem::path& getConfigPath(); … … 98 95 //! Returns the path to the data files as std::string 99 96 static std::string getDataPathString(); 100 //! Returns the path to the external data files as std::string101 static std::string getExternalDataPathString();102 97 //! Returns the path to the config files as std::string 103 98 static std::string getConfigPathString(); … … 115 110 void postUpdate(const Clock& time); 116 111 117 void loadGraphics();118 void unloadGraphics();119 120 112 void setFixedPaths(); 121 113 void setConfigurablePaths(); … … 126 118 scoped_ptr<SignalHandler> signalHandler_; 127 119 SimpleScopeGuard identifierDestroyer_; 128 SimpleScopeGuard consoleCommandDestroyer_;129 120 scoped_ptr<ConfigFileManager> configFileManager_; 130 121 scoped_ptr<Language> languageInstance_; 131 122 scoped_ptr<CoreConfiguration> configuration_; 132 scoped_ptr<TclBind> tclBind_;133 scoped_ptr<TclThreadManager> tclThreadManager_;134 scoped_ptr<Shell> shell_;135 // graphical136 scoped_ptr<GraphicsManager> graphicsManager_; //!< Interface to OGRE137 scoped_ptr<InputManager> inputManager_; //!< Interface to OIS138 scoped_ptr<GUIManager> guiManager_; //!< Interface to GUI139 123 140 124 bool bDevRun_; //!< True for runs in the build directory (not installed) 141 bool bGraphicsLoaded_;142 125 143 126 static Core* singletonPtr_s; -
code/trunk/src/libraries/core/CoreIncludes.h
r5738 r5774 80 80 */ 81 81 #define CreateFactory(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) 82 bool bCreated##ClassName##Factory = orxonox::ClassFactory<ClassName>::create(#ClassName) 90 83 91 84 /** -
code/trunk/src/libraries/core/CorePrecompiledHeaders.h
r5749 r5774 70 70 #ifdef ORXONOX_COMPILER_MSVC 71 71 72 #include <ois/OISKeyboard.h> // 1573 #include <ois/OISMouse.h> // 1574 #include <ois/OISJoyStick.h> // 1575 76 72 #include "util/SubString.h" // 14 77 73 -
code/trunk/src/libraries/core/Factory.cc
r5738 r5774 55 55 56 56 /** 57 @brief Returns the Identifier with a given network ID.58 @param id The network ID of the wanted Identifier59 @return The Identifier60 */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 else67 return 0;68 }69 70 /**71 57 @brief Adds a new Identifier to both maps. 72 58 @param name The name of the identifier … … 76 62 { 77 63 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 change84 @param oldID The old networkID85 @param newID The new networkID86 */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();99 64 } 100 65 -
code/trunk/src/libraries/core/Factory.h
r5738 r5774 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();66 64 static void createClassHierarchy(); 67 65 … … 84 82 85 83 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 Identifier87 84 }; 88 85 -
code/trunk/src/libraries/core/Game.cc
r5747 r5774 45 45 #include "Clock.h" 46 46 #include "CommandLine.h" 47 #include "ConsoleCommand.h"48 47 #include "Core.h" 49 48 #include "CoreIncludes.h" 50 49 #include "ConfigValueIncludes.h" 51 #include "GameMode.h"52 50 #include "GameState.h" 53 51 54 52 namespace orxonox 55 53 { 56 static void stop_game()57 { Game::getInstance().stop(); }58 SetConsoleCommandShortcutExternAlias(stop_game, "exit");59 60 54 std::map<std::string, GameStateInfo> Game::gameStateDeclarations_s; 61 55 Game* Game::singletonPtr_s = 0; … … 506 500 void Game::loadGraphics() 507 501 { 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 graphics515 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 catch521 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 }529 502 } 530 503 531 504 void Game::unloadGraphics() 532 505 { 533 if (GameMode::bShowsGraphics_s)534 {535 // Destroy all the GameStates that require graphics536 for (GameStateMap::iterator it = constructedStates_.begin(); it != constructedStates_.end();)537 {538 if (it->second->getInfo().bGraphicsMode)539 constructedStates_.erase(it++);540 else541 ++it;542 }543 544 core_->unloadGraphics();545 GameMode::bShowsGraphics_s = false;546 }547 506 } 548 507 … … 563 522 // If state requires graphics, load it 564 523 Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics); 565 if (gameStateDeclarations_s[name].bGraphicsMode && !GameMode::showsGraphics())524 if (gameStateDeclarations_s[name].bGraphicsMode) 566 525 this->loadGraphics(); 567 526 else -
code/trunk/src/libraries/core/Identifier.cc
r5738 r5774 38 38 #include "util/StringUtils.h" 39 39 #include "ConfigValueContainer.h" 40 #include "ConsoleCommand.h"41 40 #include "Factory.h" 42 #include "XMLPort.h"43 41 44 42 namespace orxonox … … 61 59 this->bSetName_ = false; 62 60 this->factory_ = 0; 63 this->bLoadable_ = true;64 61 65 62 this->bHasConfigValues_ = false; 66 this->bHasConsoleCommands_ = false;67 63 68 64 this->children_ = new std::set<const Identifier*>(); 69 65 this->directChildren_ = new std::set<const Identifier*>(); 70 71 // Default network ID is the class ID72 this->networkID_ = this->classID_;73 66 } 74 67 … … 85 78 delete this->factory_; 86 79 87 for (std::map<std::string, ConsoleCommand*>::iterator it = this->consoleCommands_.begin(); it != this->consoleCommands_.end(); ++it)88 delete (it->second);89 80 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)94 81 delete (it->second); 95 82 } … … 188 175 // Tell the parent we're one of it's direct children 189 176 (*it)->getDirectChildrenIntern().insert((*it)->getDirectChildrenIntern().end(), this); 190 191 // Create the super-function dependencies192 (*it)->createSuperFunctionCaller();193 177 } 194 178 } … … 240 224 241 225 /** 242 @brief Sets the network ID to a new value and changes the entry in the Factory.243 @param id The new network ID244 */245 void Identifier::setNetworkID(uint32_t id)246 {247 Factory::changeNetworkID(this, this->networkID_, id);248 this->networkID_ = id;249 }250 251 /**252 226 @brief Returns true, if the Identifier is at least of the given type. 253 227 @param identifier The identifier to compare with … … 371 345 372 346 /** 373 @brief Adds a new console command of this class.374 @param executor The executor of the command375 @param bCreateShortcut If this is true a shortcut gets created so you don't have to add the classname to access this command376 @return The executor of the command377 */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 command400 @return The executor of the requested console command401 */402 ConsoleCommand* Identifier::getConsoleCommand(const std::string& name) const403 {404 std::map<std::string, ConsoleCommand*>::const_iterator it = this->consoleCommands_.find(name);405 if (it != this->consoleCommands_.end())406 return (*it).second;407 else408 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 lowercae414 @return The executor of the requested console command415 */416 ConsoleCommand* Identifier::getLowercaseConsoleCommand(const std::string& name) const417 {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 else422 return 0;423 }424 425 /**426 @brief Returns a XMLPortParamContainer that loads a parameter of this class.427 @param paramname The name of the parameter428 @return The container429 */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 else436 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 parameter442 @param container The container443 */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 objects459 @return The container460 */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 else467 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 objects473 @param container The container474 */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 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 }517 518 /**519 347 @brief Lists the names of all Identifiers in a std::set<const Identifier*>. 520 348 @param out The outstream -
code/trunk/src/libraries/core/Identifier.h
r5738 r5774 66 66 #include "ObjectList.h" 67 67 #include "ObjectListBase.h" 68 #include "Super.h"69 68 70 69 namespace orxonox … … 107 106 bool isDirectParentOf(const Identifier* identifier) const; 108 107 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 108 /** @brief Returns the list of all existing objects of this class. @return The list */ 115 109 inline ObjectListBase* getObjects() const … … 181 175 182 176 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 218 177 /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */ 219 178 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 179 223 180 /** @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 181 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 182 232 183 /** @brief Returns the unique ID of the class */ … … 236 187 ConfigValueContainer* getConfigValueContainer(const std::string& varname); 237 188 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;251 189 252 190 void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass); … … 260 198 261 199 static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal); 262 virtual void createSuperFunctionCaller() const = 0;263 200 264 201 /** @brief Returns the map that stores all Identifiers. @return The map */ … … 305 242 bool bCreatedOneObject_; //!< True if at least one object of the given type was created (used to determine the need of storing the parents) 306 243 bool bSetName_; //!< True if the name is set 307 bool bLoadable_; //!< False = it's not permitted to load the object through XML308 244 std::string name_; //!< The name of the class the Identifier belongs to 309 245 BaseFactory* factory_; //!< The Factory, able to create new objects of the given class (if available) 310 246 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 network312 247 const unsigned int classID_; //!< Uniquely identifies a class (might not be the same as the networkID_) 313 248 static unsigned int classIDCounter_s; //!< Static counter for the unique classIDs … … 316 251 std::map<std::string, ConfigValueContainer*> configValues_; //!< A map to link the string of configurable variables with their ConfigValueContainer 317 252 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 command320 std::map<std::string, ConsoleCommand*> consoleCommands_; //!< All console commands of this class321 std::map<std::string, ConsoleCommand*> consoleCommands_LC_; //!< All console commands of this class with their names in lowercase322 323 std::map<std::string, XMLPortParamContainer*> xmlportParamContainers_; //!< All loadable parameters324 std::map<std::string, XMLPortObjectContainer*> xmlportObjectContainers_; //!< All attachable objects325 std::map<std::string, XMLPortObjectContainer*> xmlportEventContainers_; //!< All events326 253 }; 327 254 … … 344 271 class ClassIdentifier : public Identifier 345 272 { 346 #define SUPER_INTRUSIVE_DECLARATION_INCLUDE347 #include "Super.h"348 349 273 public: 350 274 static ClassIdentifier<T> *getIdentifier(); … … 360 284 ClassIdentifier() 361 285 { 362 SuperFunctionInitialization<0, T>::initialize(this);363 286 } 364 287 ~ClassIdentifier() 365 288 { 366 SuperFunctionDestruction<0, T>::destroy(this);367 289 } 368 290 … … 630 552 { return this->identifier_; } 631 553 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 554 private: 657 555 Identifier* identifier_; //!< The assigned identifier -
code/trunk/src/libraries/core/LuaState.cc
r5759 r5774 30 30 #include "LuaState.h" 31 31 32 #include <boost/filesystem.hpp> 32 33 #include <tolua/tolua++.h> 33 34 extern "C" { … … 38 39 #include "util/Debug.h" 39 40 #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;75 73 76 74 // Push 'this' pointer … … 87 85 } 88 86 89 shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename, const std::string& resourceGroup,bool bSearchOtherPaths)87 shared_ptr<ResourceInfo> LuaState::getFileInfo(const std::string& filename, bool bSearchOtherPaths) 90 88 { 91 89 shared_ptr<ResourceInfo> sourceInfo; 92 if (resourceGroup != "NoResourceGroupProvided") 93 sourceInfo = Resource::getInfo(filename, resourceGroup); 90 sourceInfo = this->getFileInfo(filename); 94 91 95 92 // Continue search if not explicitely forbidden … … 97 94 { 98 95 // Call might be relative to the file currently being processed 99 sourceInfo = Resource::getInfo(sourceFileInfo_->path + filename, sourceFileInfo_->group);96 sourceInfo = this->getFileInfo(sourceFileInfo_->path + filename); 100 97 if (sourceInfo == NULL) 101 98 { 102 99 // Maybe find something in the same group but in the root path 103 sourceInfo = Resource::getInfo(filename, sourceFileInfo_->group);100 sourceInfo = this->getFileInfo(filename); 104 101 } 105 102 } … … 107 104 } 108 105 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); 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); 112 132 if (sourceInfo != NULL) 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; 133 this->includeString(this->loadFile(sourceInfo->filename), sourceInfo); 134 else 135 COUT(2) << "LuaState: Cannot include file '" << filename << std::endl; 117 136 } 118 137 … … 129 148 } 130 149 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);150 void LuaState::doFile(const std::string& filename, bool bSearchOtherPaths) 151 { 152 shared_ptr<ResourceInfo> sourceInfo = this->getFileInfo(filename, bSearchOtherPaths); 134 153 if (sourceInfo != NULL) 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; 154 this->doString(this->loadFile(sourceInfo->filename), sourceInfo); 155 else 156 COUT(2) << "LuaState: Cannot do file '" << filename << std::endl; 139 157 } 140 158 … … 186 204 } 187 205 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);206 bool LuaState::fileExists(const std::string& filename, bool bSearchOtherPaths) 207 { 208 shared_ptr<ResourceInfo> info = this->getFileInfo(filename, bSearchOtherPaths); 191 209 if (info == NULL) 192 210 return false; -
code/trunk/src/libraries/core/LuaState.h
r5738 r5774 45 45 namespace orxonox 46 46 { 47 //! Stores basic information about a File 48 struct ResourceInfo 49 { 50 //! The file's fully qualified name 51 std::string filename; 52 //! Path name; separated by '/' and ending with '/' 53 std::string path; 54 //! Base filename 55 std::string basename; 56 }; 57 47 58 /** 48 59 @brief … … 56 67 ~LuaState(); 57 68 58 void doFile(const std::string& filename, const std::string& resourceGroup = "General",bool bSearchOtherPaths = true); // tolua_export69 void doFile(const std::string& filename, bool bSearchOtherPaths = true); // tolua_export 59 70 void doString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>()); 60 71 61 void includeFile(const std::string& filename, const std::string& resourceGroup = "General",bool bSearchOtherPaths = true); // tolua_export72 void includeFile(const std::string& filename, bool bSearchOtherPaths = true); // tolua_export 62 73 void includeString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>()); 63 74 64 75 void luaPrint(const std::string& str); // tolua_export 65 76 void luaLog(unsigned int level, const std::string& message); // tolua_export 66 bool fileExists(const std::string& filename, const std::string& resourceGroup = "General",bool bSearchOtherPaths = true); // tolua_export77 bool fileExists(const std::string& filename, bool bSearchOtherPaths = true); // tolua_export 67 78 68 79 const std::stringstream& getOutput() const { return output_; } … … 78 89 79 90 private: 80 shared_ptr<ResourceInfo> getFileInfo(const std::string& filename, const std::string& resourceGroup, bool bSearchOtherPaths); 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); 81 94 82 95 #if LUA_VERSION_NUM != 501 -
code/trunk/src/libraries/util/CMakeLists.txt
r5749 r5774 19 19 20 20 SET_SOURCE_FILES(UTIL_SRC_FILES 21 Clipboard.cc22 21 CRC32.cc 23 22 Exception.cc -
code/trunk/src/libraries/util/Exception.cc
r5747 r5774 34 34 35 35 #include "Exception.h" 36 #include <CEGUIExceptions.h>37 36 38 37 namespace orxonox … … 106 105 return ex.what(); 107 106 } 108 catch (const CEGUI::Exception& ex)109 {110 #if CEGUI_VERSION_MAJOR == 0 && CEGUI_VERSION_MINOR < 6111 return GeneralException(ex.getMessage().c_str()).getDescription();112 #else113 return GeneralException(ex.getMessage().c_str(), ex.getLine(),114 ex.getFileName().c_str(), ex.getName().c_str()).getDescription();115 #endif116 }117 107 catch (...) 118 108 {
Note: See TracChangeset
for help on using the changeset viewer.