Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 24, 2009, 11:02:42 AM (15 years ago)
Author:
rgrieder
Message:

Reverted trunk again. We might want to find a way to delete these revisions again (x3n's changes are still available as diff in the commit mails).

Location:
code/trunk/src/libraries/core
Files:
17 edited
81 copied

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/core/BaseObject.cc

    r5774 r5781  
    3333
    3434#include "BaseObject.h"
     35
     36#include <tinyxml/tinyxml.h>
     37
     38#include "util/StringUtils.h"
    3539#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"
    3648
    3749namespace orxonox
     
    4759
    4860        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        }
    4986    }
    5087
     
    5693        if (this->isInitialized())
    5794        {
    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);
    59341    }
    60342}
  • code/trunk/src/libraries/core/BaseObject.h

    r5774 r5781  
    3737#define _BaseObject_H__
    3838
     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
    3947#include "CorePrereqs.h"
     48
     49#include <map>
     50#include <list>
     51
     52#include "util/mbool.h"
    4053#include "OrxonoxClass.h"
     54#include "Super.h"
    4155
    4256namespace orxonox
    4357{
     58    class Scene;
     59    class Gametype;
     60
    4461    //! The BaseObject is the parent of all classes representing an instance in the game.
    4562    class _CoreExport BaseObject : virtual public OrxonoxClass
    4663    {
     64        template <class T> friend class XMLPortClassParamContainer;
     65
    4766        public:
    4867            BaseObject(BaseObject* creator);
    4968            virtual ~BaseObject();
     69            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    5070
    5171            /** @brief Returns if the object was initialized (passed the object registration). @return True was the object is initialized */
    5272            inline bool isInitialized() const { return this->bInitialized_; }
    5373
     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
    54133            inline void setCreator(BaseObject* creator) { this->creator_ = creator; }
    55134            inline BaseObject* getCreator() const { return this->creator_; }
    56135
     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
    57185        private:
     186            void setXMLName(const std::string& name);
     187            Template* getTemplate(unsigned int index) const;
     188
    58189            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_;
    59195            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_;
    60203    };
     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);
    61212}
    62213
  • code/trunk/src/libraries/core/CMakeLists.txt

    r5774 r5781  
    2525  DynLib.cc
    2626  DynLibManager.cc
     27  Event.cc
    2728  Game.cc
     29  GameMode.cc
    2830  GameState.cc
     31  GraphicsManager.cc
     32  GUIManager.cc
    2933  Language.cc
    3034  LuaState.cc
     35  MemoryArchive.cc
    3136  ObjectListBase.cc
    3237  OrxonoxClass.cc
     38  Resource.cc
     39  WindowEventListener.cc
    3340
    3441  # command
     42  ArgumentCompletionFunctions.cc
     43  CommandEvaluation.cc
     44  CommandExecutor.cc
    3545  CommandLine.cc
     46  ConsoleCommand.cc
     47  ConsoleCommandCompilation.cc
    3648  Executor.cc
    3749
     
    4355  # level
    4456  BaseObject.cc
     57  ClassTreeMask.cc
     58  Loader.cc
     59  Namespace.cc
     60  NamespaceNode.cc
     61  Template.cc
     62  XMLPort.cc
     63  XMLNameListener.cc
    4564
     65  # shell
     66  IRC.cc
     67  Shell.cc
     68  TclBind.cc
     69  TclThreadManager.cc
     70 
    4671  # multithreading
    4772  Thread.cc
    4873  ThreadPool.cc
    4974)
     75ADD_SUBDIRECTORY(input)
    5076
    5177ORXONOX_ADD_LIBRARY(core
    5278  FIND_HEADER_FILES
    5379  TOLUA_FILES
     80    CommandExecutor.h
     81    Loader.h
    5482    LuaState.h
    5583  DEFINE_SYMBOL
     
    6391    ${Boost_THREAD_LIBRARY}
    6492    ${Boost_DATE_TIME_LIBRARY} # Thread dependency
     93    ${CEGUI_LIBRARY}
     94    ${CEGUILUA_LIBRARY}
    6595    ${LUA_LIBRARIES}
     96    cpptcl_orxonox
     97    ogreceguirenderer_orxonox
     98    ois_orxonox
     99    tinyxml++_orxonox
    66100    tolua++_orxonox
    67101    util
  • code/trunk/src/libraries/core/ClassFactory.h

    r5774 r5781  
    5555    {
    5656        public:
    57             static bool create(const std::string& name);
     57            static bool create(const std::string& name, bool bLoadable = true);
    5858            BaseObject* fabricate(BaseObject* creator);
    5959
     
    7373    */
    7474    template <class T>
    75     bool ClassFactory<T>::create(const std::string& name)
     75    bool ClassFactory<T>::create(const std::string& name, bool bLoadable)
    7676    {
    7777        COUT(4) << "*** ClassFactory: Create entry for " << name << " in Factory." << std::endl;
    7878        ClassIdentifier<T>::getIdentifier(name)->addFactory(new ClassFactory<T>);
     79        ClassIdentifier<T>::getIdentifier()->setLoadable(bLoadable);
    7980        Factory::add(name, ClassIdentifier<T>::getIdentifier());
    8081
  • code/trunk/src/libraries/core/Clock.h

    r5774 r5781  
    3131
    3232#include "CorePrereqs.h"
    33 
    34 namespace Ogre { class Timer; }
     33#include "util/OgreForwardRefs.h"
    3534
    3635namespace orxonox
  • code/trunk/src/libraries/core/ConfigFileManager.cc

    r5774 r5781  
    3434#include "util/Math.h"
    3535#include "util/StringUtils.h"
     36#include "ConsoleCommand.h"
    3637#include "ConfigValueContainer.h"
    3738#include "Core.h"
     
    3940namespace orxonox
    4041{
     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
    4148    bool config(const std::string& classname, const std::string& varname, const std::string& value)
    4249    {
  • code/trunk/src/libraries/core/Core.cc

    r5774 r5781  
    6363#include "util/SignalHandler.h"
    6464#include "Clock.h"
     65#include "CommandExecutor.h"
    6566#include "CommandLine.h"
    6667#include "ConfigFileManager.h"
     
    6970#include "DynLibManager.h"
    7071#include "Factory.h"
     72#include "GameMode.h"
     73#include "GraphicsManager.h"
     74#include "GUIManager.h"
    7175#include "Identifier.h"
    7276#include "Language.h"
    7377#include "LuaState.h"
     78#include "Shell.h"
     79#include "TclBind.h"
     80#include "TclThreadManager.h"
     81#include "input/InputManager.h"
    7482
    7583// Boost 1.36 has some issues with deprecated functions that have been omitted
     
    109117            RegisterRootObject(CoreConfiguration);
    110118            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            }
    111127        }
    112128
     
    178194        }
    179195
     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
    180207        void initializeRandomNumberGenerator()
    181208        {
     
    201228        boost::filesystem::path modulePath_;            //!< Path to the modules
    202229        boost::filesystem::path dataPath_;              //!< Path to the data file folder
     230        boost::filesystem::path externalDataPath_;      //!< Path to the external data file folder
    203231        boost::filesystem::path configPath_;            //!< Path to the config file folder
    204232        boost::filesystem::path logPath_;               //!< Path to the log file folder
     
    209237        // Cleanup guard for identifier destruction (incl. XMLPort, configValues, consoleCommands)
    210238        : identifierDestroyer_(Identifier::destroyAllIdentifiers)
     239        // Cleanup guard for external console commands that don't belong to an Identifier
     240        , consoleCommandDestroyer_(CommandExecutor::destroyExternalCommands)
    211241        , configuration_(new CoreConfiguration()) // Don't yet create config values!
    212242        , bDevRun_(false)
     243        , bGraphicsLoaded_(false)
    213244    {
    214245        // Set the hard coded fixed paths
     
    308339        // possibility to configure everything below here
    309340        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());
    310351    }
    311352
     
    316357    Core::~Core()
    317358    {
     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;
    318399    }
    319400
     
    376457    }
    377458
     459    /*static*/ void Core::tsetExternalDataPath(const std::string& path)
     460    {
     461        getInstance().configuration_->tsetExternalDataPath(path);
     462    }
     463
    378464    /*static*/ const boost::filesystem::path& Core::getDataPath()
    379465    {
     
    383469    {
    384470        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() + '/';
    385480    }
    386481
     
    564659        {
    565660            configuration_->dataPath_  = specialConfig::dataDevDirectory;
     661            configuration_->externalDataPath_ = specialConfig::externalDataDevDirectory;
    566662            configuration_->configPath_ = specialConfig::configDevDirectory;
    567663            configuration_->logPath_    = specialConfig::logDevDirectory;
     
    629725    void Core::preUpdate(const Clock& time)
    630726    {
     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);
    631736    }
    632737
    633738    void Core::postUpdate(const Clock& time)
    634739    {
     740        if (this->bGraphicsLoaded_)
     741        {
     742            // Render (doesn't throw)
     743            this->graphicsManager_->update(time);
     744        }
    635745    }
    636746}
  • code/trunk/src/libraries/core/Core.h

    r5774 r5781  
    8585            static void  resetLanguage();
    8686
     87            static void tsetExternalDataPath(const std::string& path);
    8788            //! Returns the path to the data files as boost::filesystem::path
    8889            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();
    8992            //! Returns the path to the config files as boost::filesystem::path
    9093            static const boost::filesystem::path& getConfigPath();
     
    9598            //! Returns the path to the data files as std::string
    9699            static std::string getDataPathString();
     100            //! Returns the path to the external data files as std::string
     101            static std::string getExternalDataPathString();
    97102            //! Returns the path to the config files as std::string
    98103            static std::string getConfigPathString();
     
    110115            void postUpdate(const Clock& time);
    111116
     117            void loadGraphics();
     118            void unloadGraphics();
     119
    112120            void setFixedPaths();
    113121            void setConfigurablePaths();
     
    118126            scoped_ptr<SignalHandler>     signalHandler_;
    119127            SimpleScopeGuard              identifierDestroyer_;
     128            SimpleScopeGuard              consoleCommandDestroyer_;
    120129            scoped_ptr<ConfigFileManager> configFileManager_;
    121130            scoped_ptr<Language>          languageInstance_;
    122131            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
    123139
    124140            bool                          bDevRun_;             //!< True for runs in the build directory (not installed)
     141            bool                          bGraphicsLoaded_;
    125142
    126143            static Core* singletonPtr_s;
  • code/trunk/src/libraries/core/CoreIncludes.h

    r5774 r5781  
    8080*/
    8181#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)
    8390
    8491/**
  • code/trunk/src/libraries/core/CorePrecompiledHeaders.h

    r5774 r5781  
    7070#ifdef ORXONOX_COMPILER_MSVC
    7171
     72#include <ois/OISKeyboard.h> // 15
     73#include <ois/OISMouse.h>    // 15
     74#include <ois/OISJoyStick.h> // 15
     75
    7276#include "util/SubString.h"  // 14
    7377
  • code/trunk/src/libraries/core/Factory.cc

    r5774 r5781  
    5555
    5656    /**
     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    /**
    5771        @brief Adds a new Identifier to both maps.
    5872        @param name The name of the identifier
     
    6276    {
    6377        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();
    6499    }
    65100
  • code/trunk/src/libraries/core/Factory.h

    r5774 r5781  
    6262            static Identifier* getIdentifier(const uint32_t id);
    6363            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();
    6466            static void createClassHierarchy();
    6567
     
    8284
    8385            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
    8487    };
    8588
  • code/trunk/src/libraries/core/Game.cc

    r5774 r5781  
    4545#include "Clock.h"
    4646#include "CommandLine.h"
     47#include "ConsoleCommand.h"
    4748#include "Core.h"
    4849#include "CoreIncludes.h"
    4950#include "ConfigValueIncludes.h"
     51#include "GameMode.h"
    5052#include "GameState.h"
    5153
    5254namespace orxonox
    5355{
     56    static void stop_game()
     57        { Game::getInstance().stop(); }
     58    SetConsoleCommandShortcutExternAlias(stop_game, "exit");
     59
    5460    std::map<std::string, GameStateInfo> Game::gameStateDeclarations_s;
    5561    Game* Game::singletonPtr_s = 0;
     
    500506    void Game::loadGraphics()
    501507    {
     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        }
    502529    }
    503530
    504531    void Game::unloadGraphics()
    505532    {
     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        }
    506547    }
    507548
     
    522563        // If state requires graphics, load it
    523564        Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics);
    524         if (gameStateDeclarations_s[name].bGraphicsMode)
     565        if (gameStateDeclarations_s[name].bGraphicsMode && !GameMode::showsGraphics())
    525566            this->loadGraphics();
    526567        else
  • code/trunk/src/libraries/core/Identifier.cc

    r5774 r5781  
    3838#include "util/StringUtils.h"
    3939#include "ConfigValueContainer.h"
     40#include "ConsoleCommand.h"
    4041#include "Factory.h"
     42#include "XMLPort.h"
    4143
    4244namespace orxonox
     
    5961        this->bSetName_ = false;
    6062        this->factory_ = 0;
     63        this->bLoadable_ = true;
    6164
    6265        this->bHasConfigValues_ = false;
     66        this->bHasConsoleCommands_ = false;
    6367
    6468        this->children_ = new std::set<const Identifier*>();
    6569        this->directChildren_ = new std::set<const Identifier*>();
     70
     71        // Default network ID is the class ID
     72        this->networkID_ = this->classID_;
    6673    }
    6774
     
    7885            delete this->factory_;
    7986
     87        for (std::map<std::string, ConsoleCommand*>::iterator it = this->consoleCommands_.begin(); it != this->consoleCommands_.end(); ++it)
     88            delete (it->second);
    8089        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)
    8194            delete (it->second);
    8295    }
     
    175188                // Tell the parent we're one of it's direct children
    176189                (*it)->getDirectChildrenIntern().insert((*it)->getDirectChildrenIntern().end(), this);
     190
     191                // Create the super-function dependencies
     192                (*it)->createSuperFunctionCaller();
    177193            }
    178194        }
     
    224240
    225241    /**
     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    /**
    226252        @brief Returns true, if the Identifier is at least of the given type.
    227253        @param identifier The identifier to compare with
     
    342368        else
    343369            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;
    344516    }
    345517
  • code/trunk/src/libraries/core/Identifier.h

    r5774 r5781  
    6666#include "ObjectList.h"
    6767#include "ObjectListBase.h"
     68#include "Super.h"
    6869
    6970namespace orxonox
     
    106107            bool isDirectParentOf(const Identifier* identifier) const;
    107108
     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
    108114            /** @brief Returns the list of all existing objects of this class. @return The list */
    109115            inline ObjectListBase* getObjects() const
     
    175181
    176182
     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
    177218            /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */
    178219            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_; }
    179222
    180223            /** @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 */
    181224            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);
    182231
    183232            /** @brief Returns the unique ID of the class */
     
    187236            ConfigValueContainer* getConfigValueContainer(const std::string& varname);
    188237            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;
    189251
    190252            void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
     
    198260
    199261            static Identifier* getIdentifierSingleton(const std::string& name, Identifier* proposal);
     262            virtual void createSuperFunctionCaller() const = 0;
    200263
    201264            /** @brief Returns the map that stores all Identifiers. @return The map */
     
    242305            bool bCreatedOneObject_;                                       //!< True if at least one object of the given type was created (used to determine the need of storing the parents)
    243306            bool bSetName_;                                                //!< True if the name is set
     307            bool bLoadable_;                                               //!< False = it's not permitted to load the object through XML
    244308            std::string name_;                                             //!< The name of the class the Identifier belongs to
    245309            BaseFactory* factory_;                                         //!< The Factory, able to create new objects of the given class (if available)
    246310            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
    247312            const unsigned int classID_;                                   //!< Uniquely identifies a class (might not be the same as the networkID_)
    248313            static unsigned int classIDCounter_s;                          //!< Static counter for the unique classIDs
     
    251316            std::map<std::string, ConfigValueContainer*> configValues_;    //!< A map to link the string of configurable variables with their ConfigValueContainer
    252317            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
    253326    };
    254327
     
    271344    class ClassIdentifier : public Identifier
    272345    {
     346        #define SUPER_INTRUSIVE_DECLARATION_INCLUDE
     347        #include "Super.h"
     348
    273349        public:
    274350            static ClassIdentifier<T> *getIdentifier();
     
    284360            ClassIdentifier()
    285361            {
     362                SuperFunctionInitialization<0, T>::initialize(this);
    286363            }
    287364            ~ClassIdentifier()
    288365            {
     366                SuperFunctionDestruction<0, T>::destroy(this);
    289367            }
    290368
     
    552630                { return this->identifier_; }
    553631
     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
    554656        private:
    555657            Identifier* identifier_;            //!< The assigned identifier
  • code/trunk/src/libraries/core/LuaState.cc

    r5774 r5781  
    3030#include "LuaState.h"
    3131
    32 #include <boost/filesystem.hpp>
    3332#include <tolua/tolua++.h>
    3433extern "C" {
     
    3938#include "util/Debug.h"
    4039#include "Core.h"
     40#include "Resource.h"
    4141#include "ToluaBindCore.h"
    4242
     
    7171        // Create dummy file info
    7272        sourceFileInfo_.reset(new ResourceInfo());
     73        sourceFileInfo_->group = "General";
     74        sourceFileInfo_->size = 0;
    7375
    7476        // Push 'this' pointer
     
    8587    }
    8688
    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)
    8890    {
    8991        shared_ptr<ResourceInfo> sourceInfo;
    90         sourceInfo = this->getFileInfo(filename);
     92        if (resourceGroup != "NoResourceGroupProvided")
     93            sourceInfo = Resource::getInfo(filename, resourceGroup);
    9194
    9295        // Continue search if not explicitely forbidden
     
    9497        {
    9598            // 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);
    97100            if (sourceInfo == NULL)
    98101            {
    99102                // Maybe find something in the same group but in the root path
    100                 sourceInfo = this->getFileInfo(filename);
     103                sourceInfo = Resource::getInfo(filename, sourceFileInfo_->group);
    101104            }
    102105        }
     
    104107    }
    105108
    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);
    132112        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;
    136117    }
    137118
     
    148129    }
    149130
    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);
    153134        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;
    157139    }
    158140
     
    204186    }
    205187
    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);
    209191        if (info == NULL)
    210192            return false;
  • code/trunk/src/libraries/core/LuaState.h

    r5774 r5781  
    4545namespace orxonox
    4646{
    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 
    5847    /**
    5948    @brief
     
    6756        ~LuaState();
    6857
    69         void doFile(const std::string& filename, bool bSearchOtherPaths = true); // tolua_export
     58        void doFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
    7059        void doString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>());
    7160
    72         void includeFile(const std::string& filename, bool bSearchOtherPaths = true); // tolua_export
     61        void includeFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
    7362        void includeString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>());
    7463
    7564        void luaPrint(const std::string& str); // tolua_export
    7665        void luaLog(unsigned int level, const std::string& message); // tolua_export
    77         bool fileExists(const std::string& filename, bool bSearchOtherPaths = true); // tolua_export
     66        bool fileExists(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
    7867
    7968        const std::stringstream& getOutput() const { return output_; }
     
    8978
    9079    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);
    9481
    9582#if LUA_VERSION_NUM != 501
Note: See TracChangeset for help on using the changeset viewer.