Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2662 for code/trunk/src/core


Ignore:
Timestamp:
Feb 14, 2009, 10:17:35 PM (16 years ago)
Author:
rgrieder
Message:

Merged presentation branch back to trunk.

Location:
code/trunk
Files:
45 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/core/BaseObject.cc

    r2171 r2662  
    3636#include "CoreIncludes.h"
    3737#include "EventIncludes.h"
     38#include "Functor.h"
    3839#include "XMLPort.h"
    3940#include "XMLFile.h"
     
    6061        this->oldGametype_ = 0;
    6162
     63        this->lastLoadedXMLElement_ = 0;
     64
     65        this->functorSetMainState_ = 0;
     66        this->functorGetMainState_ = 0;
     67
    6268        this->setCreator(creator);
    6369        if (this->creator_)
     
    8288    BaseObject::~BaseObject()
    8389    {
    84         for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it)
    85             (*it)->unregisterEventListener(this);
    86 
    87         for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)
    88             it->first->removeEvent(this);
     90        if (this->isInitialized())
     91        {
     92            for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it)
     93                (*it)->unregisterEventListener(this);
     94
     95            for (std::map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)
     96                it->first->removeEvent(this);
     97
     98            if (this->functorSetMainState_)
     99                delete this->functorSetMainState_;
     100            if (this->functorGetMainState_)
     101                delete this->functorGetMainState_;
     102        }
    89103    }
    90104
     
    100114        XMLPortParam(BaseObject, "visible", setVisible, isVisible, xmlelement, mode);
    101115        XMLPortParam(BaseObject, "active", setActive, isActive, xmlelement, mode);
     116        XMLPortParam(BaseObject, "mainstate", setMainStateName, getMainStateName, xmlelement, mode);
    102117
    103118        XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*);
     
    109124            std::list<std::string> eventnames;
    110125
    111             if (mode == XMLPort::LoadObject)
     126            if (mode == XMLPort::LoadObject || mode == XMLPort::ExpandObject)
    112127            {
    113128                for (ticpp::Iterator<ticpp::Element> child = events->FirstChildElement(false); child != child.end(); child++)
     
    279294        SetEvent(BaseObject, "visibility", setVisible, event);
    280295    }
     296
     297    void BaseObject::setMainStateName(const std::string& name)
     298    {
     299        if (this->mainStateName_ != name)
     300        {
     301            this->mainStateName_ = name;
     302            if (this->functorSetMainState_)
     303                delete this->functorSetMainState_;
     304            if (this->functorGetMainState_)
     305                delete this->functorGetMainState_;
     306            this->changedMainState();
     307            if (!this->functorSetMainState_)
     308                COUT(2) << "Warning: \"" << name << "\" is not a valid MainState." << std::endl;
     309        }
     310    }
     311
     312    void BaseObject::setMainState(bool state)
     313    {
     314        if (this->functorSetMainState_)
     315            (*this->functorSetMainState_)(state);
     316        else
     317            COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl;
     318    }
     319
     320    bool BaseObject::getMainState() const
     321    {
     322        if (this->functorGetMainState_)
     323        {
     324            (*this->functorGetMainState_)();
     325            return this->functorGetMainState_->getReturnvalue();
     326        }
     327        else
     328        {
     329            COUT(2) << "Warning: No MainState defined in object \"" << this->getName() << "\" (" << this->getIdentifier()->getName() << ")" << std::endl;
     330            return false;
     331        }
     332    }
     333
     334    void BaseObject::changedMainState()
     335    {
     336        SetMainState(BaseObject, "activity",   setActive,  isActive);
     337        SetMainState(BaseObject, "visibility", setVisible, isVisible);
     338    }
    281339}
  • code/trunk/src/core/BaseObject.h

    r2171 r2662  
    3636#ifndef _BaseObject_H__
    3737#define _BaseObject_H__
     38
     39#define SetMainState(classname, statename, setfunction, getfunction) \
     40    if (this->getMainStateName() == statename) \
     41    { \
     42        this->functorSetMainState_ = createFunctor(&classname::setfunction)->setObject(this); \
     43        this->functorGetMainState_ = createFunctor(&classname::getfunction)->setObject(this); \
     44    }
    3845
    3946#include <map>
     
    5562    class _CoreExport BaseObject : virtual public OrxonoxClass
    5663    {
     64        template <class T> friend class XMLPortClassParamContainer;
     65
    5766        public:
    5867            BaseObject(BaseObject* creator);
     
    100109            virtual void changedVisibility() {}
    101110
     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
    102118            /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */
    103119            inline void setFile(const XMLFile* file) { this->file_ = file; }
     
    121137            inline Scene* getScene() const { return this->scene_; }
    122138
    123             inline void setGametype(Gametype* gametype) { this->oldGametype_ = this->gametype_; this->gametype_ = gametype; this->changedGametype(); }
     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            }
    124148            inline Gametype* getGametype() const { return this->gametype_; }
    125149            inline Gametype* getOldGametype() const { return this->oldGametype_; }
    126             virtual inline void changedGametype() {}
     150            virtual void changedGametype() {}
    127151
    128152            void fireEvent();
     
    151175
    152176        protected:
    153             std::string name_;                          //!< The name of the object
    154             std::string oldName_;                       //!< The old name of the object
    155             mbool bActive_;                             //!< True = the object is active
    156             mbool bVisible_;                            //!< True = the object is visible
     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_;
    157184
    158185        private:
     
    160187            Template* getTemplate(unsigned int index) const;
    161188
    162             bool                  bInitialized_;         //!< True if the object was initialized (passed the object registration)
    163             const XMLFile*        file_;                 //!< The XMLFile that loaded this object
    164             std::string           loaderIndentation_;    //!< Indentation of the debug output in the Loader
    165             Namespace*            namespace_;
    166             BaseObject*           creator_;
    167             Scene*                scene_;
    168             Gametype*             gametype_;
    169             Gametype*             oldGametype_;
    170             std::set<Template*>   templates_;
    171             std::map<BaseObject*, std::string> eventListeners_;
     189            bool                   bInitialized_;              //!< True if the object was initialized (passed the object registration)
     190            const XMLFile*         file_;                      //!< The XMLFile that loaded this object
     191            Element*               lastLoadedXMLElement_;      //!< Non 0 if the TinyXML attributes have already been copied to our own lowercase map
     192            std::map<std::string, std::string> xmlAttributes_; //!< Lowercase XML attributes
     193            std::string            loaderIndentation_;         //!< Indentation of the debug output in the Loader
     194            Namespace*             namespace_;
     195            BaseObject*            creator_;
     196            Scene*                 scene_;
     197            Gametype*              gametype_;
     198            Gametype*              oldGametype_;
     199            std::set<Template*>    templates_;
     200            std::map<BaseObject*,  std::string> eventListeners_;
    172201            std::list<BaseObject*> events_;
    173202            std::map<std::string, EventContainer*> eventContainers_;
     
    178207    SUPER_FUNCTION(3, BaseObject, changedVisibility, false);
    179208    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);
    180212}
    181213
  • code/trunk/src/core/CommandExecutor.cc

    r1784 r2662  
    5353    }
    5454
    55     ConsoleCommand& CommandExecutor::addConsoleCommandShortcut(ConsoleCommand* command)
     55    ConsoleCommand& CommandExecutor::addConsoleCommandShortcut(ConsoleCommand* command, bool bDeleteAtExit)
    5656    {
    5757        std::map<std::string, ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandShortcuts_.find(command->getName());
     
    6161        }
    6262
     63        // Make sure we can also delete the external ConsoleCommands that don't belong to an Identifier
     64        if (command && bDeleteAtExit)
     65        {
     66            CommandExecutor::getInstance().consoleCommandExternals_.insert(command);
     67        }
    6368
    6469        CommandExecutor::getInstance().consoleCommandShortcuts_[command->getName()] = command;
     
    647652        }
    648653    }
     654
     655    void CommandExecutor::destroyExternalCommands()
     656    {
     657        for (std::set<ConsoleCommand*>::const_iterator it = CommandExecutor::getInstance().consoleCommandExternals_.begin();
     658            it != CommandExecutor::getInstance().consoleCommandExternals_.end(); ++it)
     659            delete *it;
     660    }
    649661}
  • code/trunk/src/core/CommandExecutor.h

    r1771 r2662  
    5151            static const CommandEvaluation& getLastEvaluation();
    5252
    53             static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command);
     53            static ConsoleCommand& addConsoleCommandShortcut(ConsoleCommand* command, bool bDeleteAtExit = false);
    5454            static ConsoleCommand* getConsoleCommandShortcut(const std::string& name);
    5555            static ConsoleCommand* getLowercaseConsoleCommandShortcut(const std::string& name);
     
    6868            /** @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 */
    6969            static inline std::map<std::string, ConsoleCommand*>::const_iterator getLowercaseConsoleCommandShortcutMapEnd() { return CommandExecutor::getInstance().consoleCommandShortcuts_LC_.end(); }
     70
     71            static void destroyExternalCommands();
    7072
    7173        private:
     
    101103            std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_;
    102104            std::map<std::string, ConsoleCommand*> consoleCommandShortcuts_LC_;
     105            std::set<ConsoleCommand*>              consoleCommandExternals_;
    103106    }; // tolua_export
    104107} // tolua_export
  • code/trunk/src/core/CommandLine.cc

    r2105 r2662  
    8383    CommandLine::~CommandLine()
    8484    {
    85         for (std::map<std::string, CommandLineArgument*>::const_iterator it = cmdLineArgs_.begin();
    86             it != cmdLineArgs_.end(); ++it)
    87         {
    88             delete it->second;
    89         }
     85        CommandLine::destroyAllArguments();
    9086    }
    9187
     
    9894        static CommandLine instance;
    9995        return instance;
     96    }
     97
     98    /**
     99    @brief
     100        Destroys all command line arguments. This should be called at the end
     101        of main. Do not use before that.
     102    */
     103    void CommandLine::destroyAllArguments()
     104    {
     105        for (std::map<std::string, CommandLineArgument*>::const_iterator it = _getInstance().cmdLineArgs_.begin();
     106            it != _getInstance().cmdLineArgs_.end(); ++it)
     107            delete it->second;
     108        _getInstance().cmdLineArgs_.clear();
    100109    }
    101110
  • code/trunk/src/core/CommandLine.h

    r2103 r2662  
    155155        }
    156156
     157        static void destroyAllArguments();
    157158
    158159    private:
     
    179180        //! Holds all pointers to the arguments and serves as a search map by name.
    180181        std::map<std::string, CommandLineArgument*> cmdLineArgs_;
    181         //! Search map by chortcut for the arguments.
     182        //! Search map by shortcut for the arguments.
    182183        std::map<std::string, CommandLineArgument*> cmdLineArgsShortcut_;
    183184    };
  • code/trunk/src/core/ConfigFileManager.cc

    r2103 r2662  
    160160                if ((*it)->getIndex() > size)
    161161                    size = (*it)->getIndex();
    162         return (size + 1);
     162        if (size == 0)
     163            return 0;
     164        else
     165            return (size + 1);
    163166    }
    164167
  • code/trunk/src/core/ConfigFileManager.h

    r2103 r2662  
    3838
    3939#include "util/Math.h"
     40#include "util/OrxEnum.h"
    4041
    4142namespace orxonox
    4243{
    43     // Use unsigned int as config file type to have an arbitrary number of files
    44     class ConfigFileType
    45     {
    46     public:
    47         ConfigFileType() { }
    48         ConfigFileType(unsigned int type)              { type_ = type; }
    49         ConfigFileType(const ConfigFileType& instance) { type_ = instance.type_; }
    50 
    51         operator unsigned int() { return type_; }
    52         ConfigFileType& operator =(unsigned int type) { type_ = type; return *this; }
    53         bool operator <(const ConfigFileType& right) const   { return (type_ < right.type_); }
    54 
    55         /* *** Put the different config file types here *** */
    56         static const unsigned int NoType              = 0;
    57         static const unsigned int Settings            = 1;
    58         static const unsigned int JoyStickCalibration = 2;
    59 
    60         static const unsigned int numberOfReservedTypes = 1024;
    61 
    62     private:
    63         unsigned int type_;
     44    // Use int as config file type to have an arbitrary number of files
     45    struct ConfigFileType : OrxEnum<ConfigFileType>
     46    {
     47        OrxEnumConstructors(ConfigFileType);
     48
     49        static const int NoType              = 0;
     50        static const int Settings            = 1;
     51        static const int JoyStickCalibration = 2;
     52
     53        static const int numberOfReservedTypes = 1024;
    6454    };
    6555
  • code/trunk/src/core/ConfigValueContainer.cc

    r2171 r2662  
    273273        {
    274274            this->valueVector_.clear();
    275             for (unsigned int i = 0; i < ConfigFileManager::getInstance().getVectorSize(this->type_, this->sectionname_, this->varname_); i++)
     275            unsigned int vectorSize = ConfigFileManager::getInstance().getVectorSize(this->type_, this->sectionname_, this->varname_);
     276            for (unsigned int i = 0; i < vectorSize; i++)
    276277            {
    277278                if (i < this->defvalueStringVector_.size())
  • code/trunk/src/core/ConfigValueContainer.h

    r2171 r2662  
    109109            {
    110110                this->init(type, identifier, sectionname, varname);
    111                 this->initValue((V)defvalue);
     111                this->initValue(static_cast<V>(defvalue));
    112112            }
    113113
     
    217217            inline const std::string& getName() const
    218218                { return this->varname_; }
     219            /** @brief Retuns the name of the section this config value is in. */
     220            inline const std::string& getSectionName() const
     221                { return this->sectionname_; }
    219222            /** @brief Returns true if this config-value is a vector */
    220223            inline bool isVector() const
  • code/trunk/src/core/ConsoleCommand.h

    r2087 r2662  
    6464
    6565#define SetConsoleCommandShortcutGeneric(fakevariable, command) \
    66     orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command)
     66    orxonox::ConsoleCommand& fakevariable = orxonox::CommandExecutor::addConsoleCommandShortcut(command, true)
    6767
    6868
  • code/trunk/src/core/Core.cc

    r2171 r2662  
    4646    bool Core::bIsMaster_s      = false;
    4747
     48    Core* Core::singletonRef_s = 0;
     49
    4850    /**
    4951        @brief Constructor: Registers the object and sets the config-values.
     
    5355    {
    5456        RegisterRootObject(Core);
     57
     58        assert(Core::singletonRef_s == 0);
     59        Core::singletonRef_s = this;
     60        this->bInitializeRandomNumberGenerator_ = false;
     61
    5562        this->setConfigValues();
    56         isCreatingCoreSettings() = false;
    5763    }
    5864
     
    6268    Core::~Core()
    6369    {
    64         isCreatingCoreSettings() = true;
    65     }
    66 
    67     /**
    68         @brief Returns true if the Core instance is not yet ready and the static functions have to return a default value.
    69     */
    70     bool& Core::isCreatingCoreSettings()
    71     {
    72         static bool bCreatingCoreSettings = true;
    73         return bCreatingCoreSettings;
    74     }
    75 
    76     /**
    77         @brief Returns a unique instance of Core.
    78         @return The instance
    79     */
    80     Core& Core::getInstance()
    81     {
    82         // If bCreatingSoftDebugLevelObject is true, we're just about to create an instance of the DebugLevel class
    83         //if (Core::isCreatingCoreSettings())
    84         //{
    85         //    isCreatingCoreSettings() = false;
    86         //    //instance.setConfigValues();
    87         //}
    88 
    89         static bool firstTime = true;
    90         if (firstTime)
    91             isCreatingCoreSettings() = true;
    92 
    93         static Core instance;
    94         return instance;
     70        assert(Core::singletonRef_s);
     71        Core::singletonRef_s = 0;
    9572    }
    9673
     
    10481        SetConfigValue(softDebugLevelShell_, 1).description("The maximal level of debug output shown in the ingame shell").callback(this, &Core::debugLevelChanged);
    10582        SetConfigValue(language_, Language::getLanguage().defaultLanguage_).description("The language of the ingame text").callback(this, &Core::languageChanged);
     83        SetConfigValue(bInitializeRandomNumberGenerator_, true).description("If true, all random actions are different each time you start the game").callback(this, &Core::initializeRandomNumberGenerator);
    10684    }
    10785
     
    140118    int Core::getSoftDebugLevel(OutputHandler::OutputDevice device)
    141119    {
    142         if (!Core::isCreatingCoreSettings())
     120        switch (device)
    143121        {
    144             switch (device)
    145             {
    146             case OutputHandler::LD_All:
    147                 return Core::getInstance().softDebugLevel_;
    148             case OutputHandler::LD_Console:
    149                 return Core::getInstance().softDebugLevelConsole_;
    150             case OutputHandler::LD_Logfile:
    151                 return Core::getInstance().softDebugLevelLogfile_;
    152             case OutputHandler::LD_Shell:
    153                 return Core::getInstance().softDebugLevelShell_;
    154             default:
    155                 assert(0);
    156             }
     122        case OutputHandler::LD_All:
     123            return Core::getInstance().softDebugLevel_;
     124        case OutputHandler::LD_Console:
     125            return Core::getInstance().softDebugLevelConsole_;
     126        case OutputHandler::LD_Logfile:
     127            return Core::getInstance().softDebugLevelLogfile_;
     128        case OutputHandler::LD_Shell:
     129            return Core::getInstance().softDebugLevelShell_;
     130        default:
     131            assert(0);
     132            return 2;
    157133        }
    158 
    159         // Return a constant value while we're creating the object
    160         return 2;
    161134    }
    162135
     
    168141     void Core::setSoftDebugLevel(OutputHandler::OutputDevice device, int level)
    169142     {
    170         if (!Core::isCreatingCoreSettings())
    171         {
    172             if (device == OutputHandler::LD_All)
    173                 Core::getInstance().softDebugLevel_ = level;
    174             else if (device == OutputHandler::LD_Console)
    175                 Core::getInstance().softDebugLevelConsole_ = level;
    176             else if (device == OutputHandler::LD_Logfile)
    177                 Core::getInstance().softDebugLevelLogfile_ = level;
    178             else if (device == OutputHandler::LD_Shell)
    179                 Core::getInstance().softDebugLevelShell_ = level;
     143        if (device == OutputHandler::LD_All)
     144            Core::getInstance().softDebugLevel_ = level;
     145        else if (device == OutputHandler::LD_Console)
     146            Core::getInstance().softDebugLevelConsole_ = level;
     147        else if (device == OutputHandler::LD_Logfile)
     148            Core::getInstance().softDebugLevelLogfile_ = level;
     149        else if (device == OutputHandler::LD_Shell)
     150            Core::getInstance().softDebugLevelShell_ = level;
    180151
    181             OutputHandler::setSoftDebugLevel(device, level);
    182         }
     152        OutputHandler::setSoftDebugLevel(device, level);
    183153     }
    184154
     
    188158    const std::string& Core::getLanguage()
    189159    {
    190         if (!Core::isCreatingCoreSettings())
    191             return Core::getInstance().language_;
    192 
    193         return Language::getLanguage().defaultLanguage_;
     160        return Core::getInstance().language_;
    194161    }
    195162
     
    209176        ResetConfigValue(language_);
    210177    }
     178
     179    void Core::initializeRandomNumberGenerator()
     180    {
     181        static bool bInitialized = false;
     182        if (!bInitialized && this->bInitializeRandomNumberGenerator_)
     183        {
     184            srand(time(0));
     185            rand();
     186            bInitialized = true;
     187        }
     188    }
    211189}
  • code/trunk/src/core/Core.h

    r2171 r2662  
    4040#include "CorePrereqs.h"
    4141
     42#include <cassert>
    4243#include "OrxonoxClass.h"
    4344#include "util/OutputHandler.h"
     
    4950    {
    5051        public:
    51             static Core& getInstance();
    52             static bool& isCreatingCoreSettings();
     52            Core();
     53            ~Core();
    5354            void setConfigValues();
    5455            void debugLevelChanged();
    5556            void languageChanged();
    5657
    57             static int getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);
    58             static void setSoftDebugLevel(OutputHandler::OutputDevice device, int level);
     58            static Core& getInstance() { assert(Core::singletonRef_s); return *Core::singletonRef_s; }
     59
     60            static int   getSoftDebugLevel(OutputHandler::OutputDevice device = OutputHandler::LD_All);
     61            static void  setSoftDebugLevel(OutputHandler::OutputDevice device, int level);
    5962            static const std::string& getLanguage();
    60             static void resetLanguage();
     63            static void  resetLanguage();
    6164
    6265            // fast access global variables.
     
    7376
    7477        private:
     78            Core(const Core&);
    7579            void resetLanguageIntern();
    76 
    77             Core();
    78             Core(const Core& other);
    79             virtual ~Core();
     80            void initializeRandomNumberGenerator();
    8081
    8182            int softDebugLevel_;                            //!< The debug level
     
    8485            int softDebugLevelShell_;                       //!< The debug level for the ingame shell
    8586            std::string language_;                          //!< The language
     87            bool bInitializeRandomNumberGenerator_;          //!< If true, srand(time(0)) is called
    8688
    8789            static bool bShowsGraphics_s;                   //!< global variable that tells whether to show graphics
     
    9092            static bool bIsStandalone_s;
    9193            static bool bIsMaster_s;
     94
     95            static Core* singletonRef_s;
    9296    };
    9397}
  • code/trunk/src/core/CorePrereqs.h

    r2087 r2662  
    6969    {
    7070      LoadObject,
    71       SaveObject
     71      SaveObject,
     72      ExpandObject
    7273    };
    7374  }
     
    132133  class LanguageEntry;
    133134  class Loader;
     135  class LuaBind;
    134136  class MetaObjectList;
    135137  class MetaObjectListElement;
  • code/trunk/src/core/Factory.cc

    r2171 r2662  
    5858        @return The Identifier
    5959    */
    60     Identifier* Factory::getIdentifier(const unsigned int id)
     60    Identifier* Factory::getIdentifier(const uint32_t id)
    6161    {
    62         std::map<unsigned int, Identifier*>::const_iterator it = getFactoryPointer()->identifierNetworkIDMap_.find(id);
     62        std::map<uint32_t, Identifier*>::const_iterator it = getFactoryPointer()->identifierNetworkIDMap_.find(id);
    6363        if (it != getFactoryPointer()->identifierNetworkIDMap_.end())
    6464            return it->second;
     
    8585        @param newID The new networkID
    8686    */
    87     void Factory::changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID)
     87    void Factory::changeNetworkID(Identifier* identifier, const uint32_t oldID, const uint32_t newID)
    8888    {
    8989        getFactoryPointer()->identifierNetworkIDMap_.erase(oldID);
  • code/trunk/src/core/Factory.h

    r2171 r2662  
    4949#include <map>
    5050#include <string>
     51#include "util/Integers.h"
    5152
    5253namespace orxonox
     
    6061        public:
    6162            static Identifier* getIdentifier(const std::string& name);
    62             static Identifier* getIdentifier(const unsigned int id);
     63            static Identifier* getIdentifier(const uint32_t id);
    6364            static void add(const std::string& name, Identifier* identifier);
    64             static void changeNetworkID(Identifier* identifier, const unsigned int oldID, const unsigned int newID);
     65            static void changeNetworkID(Identifier* identifier, const uint32_t oldID, const uint32_t newID);
    6566            static void createClassHierarchy();
    6667
     
    8384
    8485            std::map<std::string, Identifier*> identifierStringMap_;            //!< The map, mapping the name with the Identifier
    85             std::map<unsigned int, Identifier*> identifierNetworkIDMap_;        //!< The map, mapping the network ID with the Identifier
     86            std::map<uint32_t, Identifier*> identifierNetworkIDMap_;        //!< The map, mapping the network ID with the Identifier
    8687    };
    8788
  • code/trunk/src/core/Functor.h

    r2087 r2662  
    167167            }
    168168
    169             FunctorMember* setObject(T* object)
     169            FunctorMember<T>* setObject(T* object)
    170170            {
    171171                this->bConstObject_ = false;
     
    174174            }
    175175
    176             FunctorMember* setObject(const T* object)
     176            FunctorMember<T>* setObject(const T* object)
    177177            {
    178178                this->bConstObject_ = true;
  • code/trunk/src/core/Identifier.cc

    r2171 r2662  
    9393        for (std::map<std::string, XMLPortObjectContainer*>::iterator it = this->xmlportObjectContainers_.begin(); it != this->xmlportObjectContainers_.end(); ++it)
    9494            delete (it->second);
     95        for (std::vector<Functor*>::iterator it = this->constructionCallbacks_.begin(); it != this->constructionCallbacks_.end(); ++it)
     96            delete *it;
     97    }
     98
     99    /**
     100        @brief Returns the identifier map with the names as received by typeid(). This is only used internally.
     101    */
     102    std::map<std::string, Identifier*>& Identifier::getTypeIDIdentifierMap()
     103    {
     104        static std::map<std::string, Identifier*> identifiers;    //!< The map to store all Identifiers.
     105        return identifiers;
    95106    }
    96107
     
    103114    Identifier* Identifier::getIdentifierSingleton(const std::string& name, Identifier* proposal)
    104115    {
    105         static std::map<std::string, Identifier*> identifiers;    //!< The map to store all Identifiers.
    106         std::map<std::string, Identifier*>::const_iterator it = identifiers.find(name);
    107 
    108         if (it != identifiers.end())
     116        std::map<std::string, Identifier*>::const_iterator it = getTypeIDIdentifierMap().find(name);
     117
     118        if (it != getTypeIDIdentifierMap().end())
    109119        {
    110120            // There is already an entry: return it and delete the proposal
     
    115125        {
    116126            // There is no entry: put the proposal into the map and return it
    117             identifiers[name] = proposal;
     127            getTypeIDIdentifierMap()[name] = proposal;
    118128            return proposal;
    119129        }
     
    192202    void Identifier::destroyAllIdentifiers()
    193203    {
    194         for (std::map<std::string, Identifier*>::iterator it = Identifier::getIdentifierMapIntern().begin(); it != Identifier::getIdentifierMapIntern().end(); ++it)
     204        for (std::map<std::string, Identifier*>::iterator it = Identifier::getTypeIDIdentifierMap().begin(); it != Identifier::getTypeIDIdentifierMap().end(); ++it)
    195205            delete (it->second);
    196206    }
     
    235245        @param id The new network ID
    236246    */
    237     void Identifier::setNetworkID(unsigned int id)
     247    void Identifier::setNetworkID(uint32_t id)
    238248    {
    239249        Factory::changeNetworkID(this, this->classID_, id);
  • code/trunk/src/core/Identifier.h

    r2171 r2662  
    6868#include "Super.h"
    6969#include "Functor.h"
     70#include "util/Integers.h"
    7071#include "util/Debug.h"
    7172#include "util/String.h"
     
    230231
    231232            /** @brief Returns the network ID to identify a class through the network. @return the network ID */
    232             inline const unsigned int getNetworkID() const { return this->classID_; }
     233            inline const uint32_t getNetworkID() const { return this->classID_; }
    233234
    234235            /** @brief Sets the network ID to a new value. @param id The new value */
    235             void setNetworkID(unsigned int id);
     236            void setNetworkID(uint32_t id);
    236237
    237238            void addConfigValueContainer(const std::string& varname, ConfigValueContainer* container);
     
    256257
    257258            void initializeClassHierarchy(std::set<const Identifier*>* parents, bool bRootClass);
     259
     260            static void destroyAllIdentifiers();
    258261
    259262        protected:
     
    299302            }
    300303
     304            static std::map<std::string, Identifier*>& getTypeIDIdentifierMap();
     305
    301306            void initialize(std::set<const Identifier*>* parents);
    302 
    303             static void destroyAllIdentifiers();
    304307
    305308            std::set<const Identifier*> parents_;                          //!< The parents of the class the Identifier belongs to
     
    315318            BaseFactory* factory_;                                         //!< The Factory, able to create new objects of the given class (if available)
    316319            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)
    317             unsigned int classID_;                                         //!< The network ID to identify a class through the network
     320            uint32_t classID_;                                             //!< The network ID to identify a class through the network
    318321
    319322            bool bHasConfigValues_;                                        //!< True if this class has at least one assigned config value
  • code/trunk/src/core/Iterator.h

    r2171 r2662  
    9696            inline Iterator(ObjectListElement<O>* element)
    9797            {
    98                 this->element_ = (element) ? (ObjectListBaseElement*)element : 0;
     98                this->element_ = (element) ? static_cast<ObjectListBaseElement*>(element) : 0;
    9999                this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
    100100                this->iterator_ = this->list_->registerIterator(this);
     
    108108            inline Iterator(const ObjectListIterator<O>& other)
    109109            {
    110                 this->element_ = (other.element_) ? (ObjectListBaseElement*)other.element_ : 0;
     110                this->element_ = (other.element_) ? static_cast<ObjectListBaseElement*>(other.element_) : 0;
    111111                this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
    112112                this->iterator_ = this->list_->registerIterator(this);
     
    163163                    this->list_->unregisterIterator(this->iterator_);
    164164
    165                 this->element_ = (element) ? (ObjectListBaseElement*)element : 0;
     165                this->element_ = (element) ? static_cast<ObjectListBaseElement*>(element) : 0;
    166166                this->list_ = ClassIdentifier<O>::getIdentifier()->getObjects();
    167167                this->iterator_ = this->list_->registerIterator(this);
  • code/trunk/src/core/Language.cc

    r2171 r2662  
    8787    // ###        Language         ###
    8888    // ###############################
     89
     90    Language* Language::singletonRef_s = 0;
     91
    8992    /**
    9093        @brief Constructor: Reads the default language file and sets some values.
     
    9295    Language::Language()
    9396    {
     97        assert(singletonRef_s == 0);
     98        singletonRef_s = this;
     99
    94100        this->defaultLanguage_ = "default";
    95101        this->defaultLocalisation_ = "ERROR: LANGUAGE ENTRY DOESN'T EXIST!";
     
    106112        for (std::map<std::string, LanguageEntry*>::iterator it = this->languageEntries_.begin(); it != this->languageEntries_.end(); ++it)
    107113            delete (it->second);
    108     }
    109 
    110     /**
    111         @brief Returns a reference to the only existing instance of the Language class and calls the setConfigValues() function.
    112         @return The reference to the only existing instance
    113     */
    114     Language& Language::getLanguage()
    115     {
    116         static Language instance = Language();
    117         return instance;
     114
     115        assert(singletonRef_s);
     116        singletonRef_s = 0;
    118117    }
    119118
     
    233232            if ((lineString != "") && (lineString.size() > 0))
    234233            {
    235                 unsigned int pos = lineString.find('=');
     234                size_t pos = lineString.find('=');
    236235
    237236                // Check if the length is at least 3 and if there's an entry before and behind the =
     
    279278            if ((lineString != "") && (lineString.size() > 0))
    280279            {
    281                 unsigned int pos = lineString.find('=');
     280                size_t pos = lineString.find('=');
    282281
    283282                // Check if the length is at least 3 and if there's an entry before and behind the =
  • code/trunk/src/core/Language.h

    r2171 r2662  
    5050#include <map>
    5151#include <string>
     52#include <cassert>
    5253
    5354#define AddLanguageEntry(label, fallbackstring) \
     
    116117
    117118        public:
    118             static Language& getLanguage();
     119            Language();
     120            ~Language();
     121
     122            static Language& getLanguage() { assert(singletonRef_s); return *singletonRef_s; }
    119123            void addEntry(const LanguageEntryLabel& label, const std::string& entry);
    120124            const std::string& getLocalisation(const LanguageEntryLabel& label) const;
    121125
    122126        private:
    123             Language();
    124             Language(const Language& language);     // don't copy
    125             virtual ~Language();
     127            Language(const Language&);
    126128
    127129            void readDefaultLanguageFile();
     
    134136            std::string defaultLocalisation_;                       //!< The returned string, if an entry unavailable entry is requested
    135137            std::map<std::string, LanguageEntry*> languageEntries_; //!< A map to store all LanguageEntry objects and their labels
     138
     139            static Language* singletonRef_s;
    136140    };
    137141}
  • code/trunk/src/core/Loader.cc

    r2171 r2662  
    120120
    121121        // let Lua work this out:
    122         LuaBind* lua = LuaBind::getInstance();
    123         lua->clearLuaOutput();
    124         lua->loadFile(file->getFilename(), true);
    125         lua->run();
     122        LuaBind& lua = LuaBind::getInstance();
     123        lua.clearLuaOutput();
     124        lua.loadFile(file->getFilename(), true);
     125        lua.run();
    126126
    127127        try
     
    135135            ticpp::Document xmlfile;
    136136            //xmlfile.ToDocument();
    137             xmlfile.Parse(lua->getLuaOutput(), true);
     137            xmlfile.Parse(lua.getLuaOutput(), true);
    138138
    139139            ticpp::Element rootElement;
  • code/trunk/src/core/LuaBind.cc

    r2508 r2662  
    4040namespace orxonox
    4141{
    42   LuaBind* LuaBind::singletonRef = NULL;
     42  LuaBind* LuaBind::singletonRef_s = NULL;
    4343
    4444  LuaBind::LuaBind()
    4545  {
     46    assert(LuaBind::singletonRef_s == 0);
     47    LuaBind::singletonRef_s = this;
     48
    4649    luaState_ = lua_open();
    4750    luaSource_ = "";
  • code/trunk/src/core/LuaBind.h

    r2087 r2662  
    4242}
    4343
     44#include <cassert>
    4445#include <list>
    4546#include <string>
     
    5859
    5960    public:
    60       inline static LuaBind* getInstance() { if (!LuaBind::singletonRef) LuaBind::singletonRef = new LuaBind(); return LuaBind::singletonRef; } // tolua_export
    61       inline ~LuaBind() { LuaBind::singletonRef = NULL; };
     61      LuaBind();
     62      inline ~LuaBind() { assert(singletonRef_s); LuaBind::singletonRef_s = NULL; };
     63
     64      inline static LuaBind& getInstance() { assert(singletonRef_s); return *LuaBind::singletonRef_s; } // tolua_export
    6265
    6366    void loadFile(std::string filename, bool luaTags);
     
    8386
    8487    private:
    85       LuaBind();
    86       static LuaBind* singletonRef;
     88      static LuaBind* singletonRef_s;
    8789
    8890      std::string luaSource_;
  • code/trunk/src/core/ObjectListIterator.h

    r1747 r2662  
    123123            {
    124124                if (this->element_)
    125                     this->element_ = (ObjectListElement<T>*)this->element_->next_;
     125                    this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_);
    126126                return *this;
    127127            }
     
    135135                ObjectListIterator<T> copy = *this;
    136136                if (this->element_)
    137                     this->element_ = (ObjectListElement<T>*)this->element_->next_;
     137                    this->element_ = static_cast<ObjectListElement<T>*>(this->element_->next_);
    138138                return copy;
    139139            }
     
    146146            {
    147147                if (this->element_)
    148                     this->element_ = (ObjectListElement<T>*)this->element_->prev_;
     148                    this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_);
    149149                return *this;
    150150            }
     
    158158                ObjectListIterator<T> copy = *this;
    159159                if (this->element_)
    160                     this->element_ = (ObjectListElement<T>*)this->element_->prev_;
     160                    this->element_ = static_cast<ObjectListElement<T>*>(this->element_->prev_);
    161161                return copy;
    162162            }
  • code/trunk/src/core/RootGameState.cc

    r2103 r2662  
    3131#include "util/Debug.h"
    3232#include "util/Exception.h"
    33 #include "Core.h"
    3433#include "Clock.h"
    3534#include "CommandLine.h"
     
    123122    /**
    124123    @brief
     124        Main loop of the orxonox game.
    125125        Starts the game. The little 'while' denotes the main loop.
    126126        Whenever the root state is selected, the game ends.
    127127    @param name
    128128        State to start with (usually main menu or specified by command line)
     129    @note
     130        We use the Ogre::Timer to measure time since it uses the most precise
     131        method an a platform (however the windows timer lacks time when under
     132        heavy kernel load!).
    129133    */
    130134    void RootGameState::start()
    131135    {
    132 #ifdef NDEBUG
     136        // Don't catch errors when having a debugger in msvc
     137#if ORXONOX_COMPILER != ORXONOX_COMPILER_MSVC || defined(NDEBUG)
    133138        try
    134139        {
     
    136141            // start global orxonox time
    137142            Clock clock;
    138 
    139             // create the Core settings to configure the output level
    140             Core::getInstance();
    141143
    142144            this->activate();
     
    156158
    157159            this->deactivate();
    158 #ifdef NDEBUG
     160#if ORXONOX_COMPILER != ORXONOX_COMPILER_MSVC || defined(NDEBUG)
    159161        }
    160162        // Note: These are all unhandled exceptions that should not have made its way here!
     
    162164        catch (std::exception& ex)
    163165        {
    164             COUT(1) << ex.what() << std::endl;
    165             COUT(1) << "Program aborted." << std::endl;
     166            COUT(0) << ex.what() << std::endl;
     167            COUT(0) << "Program aborted." << std::endl;
     168            abort();
    166169        }
    167170        // anything that doesn't inherit from std::exception
    168171        catch (...)
    169172        {
    170             COUT(1) << "An unidentifiable exception has occured. Program aborted." << std::endl;
     173            COUT(0) << "An unidentifiable exception has occured. Program aborted." << std::endl;
     174            abort();
    171175        }
    172176#endif
  • code/trunk/src/core/RootGameState.h

    r2103 r2662  
    4848        void gotoState(const std::string& name);
    4949
    50         std::string           stateRequest_;
     50        std::string stateRequest_;
    5151    };
    5252}
  • code/trunk/src/core/Shell.cc

    r1792 r2662  
    7575
    7676        this->outputBuffer_.registerListener(this);
    77         OutputHandler::getOutStream().setOutputBuffer(this->outputBuffer_);
     77        OutputHandler::getOutStream().setOutputBuffer(&this->outputBuffer_);
    7878
    7979        this->setConfigValues();
     
    8484    Shell::~Shell()
    8585    {
     86        OutputHandler::getOutStream().setOutputBuffer(0);
    8687        if (this->inputBuffer_)
    8788            delete this->inputBuffer_;
  • code/trunk/src/core/Super.h

    r2171 r2662  
    9999            \
    100100            static void apply(void* temp) {} \
     101            \
    101102            static void apply(baseclass* temp) \
    102103            { \
     
    104105                for (std::set<const Identifier*>::iterator it = identifier->getDirectChildrenIntern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it) \
    105106                { \
     107                    if (((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) \
     108                    { \
     109                        delete ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_; \
     110                        ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_ = 0; \
     111                        ((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ = false; \
     112                    } \
     113                    \
    106114                    if (!((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_) \
    107115                    { \
     
    163171                for (std::set<const Identifier*>::iterator it = identifier->getDirectChildrenIntern().begin(); it != identifier->getDirectChildrenIntern().end(); ++it)
    164172                {
     173                    // Check if the caller is a fallback-caller
     174                    if (((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ && ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_)
     175                    {
     176                        // Delete the fallback caller an prepare to get a real caller
     177                        delete ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_;
     178                        ((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_ = 0;
     179                        ((ClassIdentifier<T>*)(*it))->bSuperFunctionCaller_##functionname##_isFallback_ = false;
     180                    }
     181
    165182                    // Check if there's not already a caller
    166183                    if (!((ClassIdentifier<T>*)(*it))->superFunctionCaller_##functionname##_)
     
    183200        struct SuperFunctionCondition<functionnumber, baseclass, 0, templatehack2> \
    184201        { \
    185             // The check function just behaves like the fallback - it advances to the check for the next super-function (functionnumber + 1)
     202            // The check function acts like the fallback - it advances to the check for the next super-function (functionnumber + 1)
    186203            static void check() \
    187204            { \
     
    233250    #define SUPER_processEvent(classname, functionname, ...) \
    234251        SUPER_ARGS(classname, functionname, __VA_ARGS__)
     252
     253    #define SUPER_changedScale(classname, functionname, ...) \
     254        SUPER_NOARGS(classname, functionname)
     255
     256    #define SUPER_changedMainState(classname, functionname, ...) \
     257        SUPER_NOARGS(classname, functionname)
     258
     259    #define SUPER_changedOwner(classname, functionname, ...) \
     260        SUPER_NOARGS(classname, functionname)
     261
     262    #define SUPER_changedOverlayGroup(classname, functionname, ...) \
     263        SUPER_NOARGS(classname, functionname)
     264
     265    #define SUPER_changedName(classname, functionname, ...) \
     266        SUPER_NOARGS(classname, functionname)
     267
     268    #define SUPER_changedGametype(classname, functionname, ...) \
     269        SUPER_NOARGS(classname, functionname)
    235270    // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    236271
     
    292327            }; \
    293328            \
     329            class _CoreExport SuperFunctionCaller_##functionname \
     330            { \
     331                public: \
     332                    virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0; \
     333                    virtual ~SuperFunctionCaller_##functionname () {} \
     334            }; \
     335            \
     336            template <class T> \
     337            class SuperFunctionClassCaller_purevirtualfallback_##functionname : public SuperFunctionCaller_##functionname \
     338            { \
     339                public: \
     340                    inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) \
     341                    { \
     342                    } \
     343            }; \
     344            \
    294345            template <class T> \
    295346            struct SuperFunctionInitialization<functionnumber, T> \
     
    297348                static void initialize(ClassIdentifier<T>* identifier) \
    298349                { \
    299                     identifier->superFunctionCaller_##functionname##_ = 0; \
     350                    identifier->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_purevirtualfallback_##functionname <T>; \
     351                    identifier->bSuperFunctionCaller_##functionname##_isFallback_ = true; \
    300352                    SuperFunctionInitialization<functionnumber + 1, T>::initialize(identifier); \
    301353                } \
     
    313365            }; \
    314366            \
    315             class _CoreExport SuperFunctionCaller_##functionname \
    316             { \
    317                 public: \
    318                     virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0; \
    319                     virtual ~SuperFunctionCaller_##functionname () {} \
    320             }; \
    321             \
    322367            template <class T> \
    323368            class SuperFunctionClassCaller_##functionname : public SuperFunctionCaller_##functionname \
     
    366411        };
    367412
    368         // Initializes the SuperFunctionCaller-pointer with zero.
     413        // Baseclass of the super-function caller. The real call will be done by a
     414        // templatized subclass through the virtual () operator.
     415        class _CoreExport SuperFunctionCaller_##functionname
     416        {
     417            public:
     418                virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0;
     419                virtual ~SuperFunctionCaller_##functionname () {}
     420        };
     421
     422        // Fallback if the base is pure virtual
     423        template <class T>
     424        class SuperFunctionClassCaller_purevirtualfallback_##functionname : public SuperFunctionCaller_##functionname
     425        {
     426            public:
     427                // Fallback does nothing
     428                inline void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) )
     429                {
     430                }
     431        };
     432
     433        // Initializes the SuperFunctionCaller-pointer with a fallback caller in case the base function is pure virtual
    369434        template <class T>
    370435        struct SuperFunctionInitialization<functionnumber, T>
     
    372437            static void initialize(ClassIdentifier<T>* identifier)
    373438            {
    374                 identifier->superFunctionCaller_##functionname##_ = 0;
     439                identifier->superFunctionCaller_##functionname##_ = new SuperFunctionClassCaller_purevirtualfallback_##functionname <T>;
     440                identifier->bSuperFunctionCaller_##functionname##_isFallback_ = true;
    375441
    376442                // Calls the initialization of the next super-function (functionnumber + 1)
     
    391457                SuperFunctionDestruction<functionnumber + 1, T>::destroy(identifier);
    392458            }
    393         };
    394 
    395         // Baseclass of the super-function caller. The real call will be done by a
    396         // templatized subclass through the virtual () operator.
    397         class _CoreExport SuperFunctionCaller_##functionname
    398         {
    399             public:
    400                 virtual void operator()( SUPER_CALL_ARGUMENTS##hasarguments(__VA_ARGS__) ) = 0;
    401                 virtual ~SuperFunctionCaller_##functionname () {}
    402459        };
    403460
     
    441498            (event)
    442499        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     500
     501        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(5, changedScale, false)
     502            ()
     503        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     504
     505        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(6, changedMainState, false)
     506            ()
     507        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     508
     509        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(7, changedOwner, false)
     510            ()
     511        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     512
     513        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(8, changedOverlayGroup, false)
     514            ()
     515        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     516
     517        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(9, changedName, false)
     518            ()
     519        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     520
     521        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(10, changedGametype, false)
     522            ()
     523        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
    443524        // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    444525
     
    476557        #ifndef SUPER_INTRUSIVE_DECLARATION
    477558          #define SUPER_INTRUSIVE_DECLARATION(functionname) \
    478             SuperFunctionCaller_##functionname * superFunctionCaller_##functionname##_
     559            SuperFunctionCaller_##functionname * superFunctionCaller_##functionname##_; \
     560            bool bSuperFunctionCaller_##functionname##_isFallback_
    479561        #endif
    480562
     
    488570    SUPER_INTRUSIVE_DECLARATION(changedVisibility);
    489571    SUPER_INTRUSIVE_DECLARATION(processEvent);
     572    SUPER_INTRUSIVE_DECLARATION(changedScale);
     573    SUPER_INTRUSIVE_DECLARATION(changedMainState);
     574    SUPER_INTRUSIVE_DECLARATION(changedOwner);
     575    SUPER_INTRUSIVE_DECLARATION(changedOverlayGroup);
     576    SUPER_INTRUSIVE_DECLARATION(changedName);
     577    SUPER_INTRUSIVE_DECLARATION(changedGametype);
    490578    // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    491579
  • code/trunk/src/core/Template.cc

    r2261 r2662  
    4343
    4444        this->bIsLink_ = false;
     45        this->bLoadDefaults_ = true;
    4546        this->bIsReturningXMLElement_ = false;
    4647        this->baseclassIdentifier_ = 0;
     
    5657        SUPER(Template, XMLPort, xmlelement, mode);
    5758
    58         XMLPortParam(Template, "link", setLink, getLink, xmlelement, mode);
    59         XMLPortParam(Template, "baseclass", setBaseclass, getBaseclass, xmlelement, mode);
     59        XMLPortParam(Template, "link",      setLink,         getLink,         xmlelement, mode);
     60        XMLPortParam(Template, "baseclass", setBaseclass,    getBaseclass,    xmlelement, mode);
     61        XMLPortParam(Template, "defaults",  setLoadDefaults, getLoadDefaults, xmlelement, mode).defaultValues(true);
    6062
    6163        Element* element = xmlelement.FirstChildElement(false);
     
    7072    void Template::changedName()
    7173    {
     74        SUPER(Template, changedName);
     75
    7276        if (this->getName() != "")
    7377        {
     
    134138
    135139        Element temp = ((TiXmlElement*)&this->getXMLElement());
    136         object->XMLPort(temp, XMLPort::LoadObject);
     140
     141        if (this->bLoadDefaults_)
     142            object->XMLPort(temp, XMLPort::LoadObject);
     143        else
     144            object->XMLPort(temp, XMLPort::ExpandObject);
    137145    }
    138146
  • code/trunk/src/core/Template.h

    r2261 r2662  
    5353                { return this->link_; }
    5454
     55            inline void setLoadDefaults(bool bLoadDefaults)
     56                { this->bLoadDefaults_ = bLoadDefaults; }
     57            inline bool getLoadDefaults() const
     58                { return this->bLoadDefaults_; }
     59
    5560            inline void setXMLElement(const TiXmlElement& xmlelement)
    5661                { this->xmlelement_ = xmlelement; }
     
    7580            Identifier* baseclassIdentifier_;
    7681            bool bIsLink_;
     82            bool bLoadDefaults_;
    7783            mutable bool bIsReturningXMLElement_;
    7884    };
  • code/trunk/src/core/XMLFile.h

  • code/trunk/src/core/XMLIncludes.h

    r2261 r2662  
    6464namespace orxonox
    6565{
    66     typedef ticpp::Document Document;
    67     typedef ticpp::Element Element;
    68     typedef ticpp::Declaration Declaration;
    69     typedef ticpp::StylesheetReference StylesheetReference;
    70     typedef ticpp::Text Text;
    71     typedef ticpp::Comment Comment;
    72     typedef ticpp::Attribute Attribute;
     66    using ticpp::Document;
     67    using ticpp::Element;
     68    using ticpp::Declaration;
     69    using ticpp::StylesheetReference;
     70    using ticpp::Text;
     71    using ticpp::Comment;
     72    using ticpp::Attribute;
    7373}
  • code/trunk/src/core/XMLPort.h

    r2171 r2662  
    4343#include "CorePrereqs.h"
    4444
     45#include <cassert>
    4546#include "util/Debug.h"
    4647#include "util/Exception.h"
     
    7475    static ExecutorMember<classname>* xmlcontainer##loadfunction##savefunction##saveexecutor = orxonox::createExecutor(orxonox::createFunctor(&classname::savefunction), std::string( #classname ) + "::" + #savefunction); \
    7576    XMLPortParamGeneric(xmlcontainer##loadfunction##savefunction, classname, classname, this, paramname, xmlcontainer##loadfunction##savefunction##loadexecutor, xmlcontainer##loadfunction##savefunction##saveexecutor, xmlelement, mode)
     77
     78/**
     79    @brief Declares an XML attribute with a name, which will be set through a variable.
     80    @param classname The name of the class owning this param
     81    @param paramname The name of the attribute
     82    @param variable Name of the variable used to save and load the value
     83    @param xmlelement The XMLElement, you get this from the XMLPort function
     84    @param mode The mode (load or save), you get this from the XMLPort function
     85
     86    In the XML file, a param or attribute will be set like this:
     87    <classname paramname="value" />
     88
     89    The macro will then store "value" in the variable or read it when saving.
     90*/
     91#define XMLPortParamVariable(classname, paramname, variable, xmlelement, mode) \
     92    XMLPortVariableHelperClass xmlcontainer##variable##dummy((void*)&variable); \
     93    static ExecutorMember<orxonox::XMLPortVariableHelperClass>* xmlcontainer##variable##loadexecutor = static_cast<ExecutorMember<orxonox::XMLPortVariableHelperClass>*>(orxonox::createExecutor(orxonox::createFunctor(orxonox::XMLPortVariableHelperClass::getLoader(variable)), std::string( #classname ) + "::" + #variable + "loader")); \
     94    static ExecutorMember<orxonox::XMLPortVariableHelperClass>* xmlcontainer##variable##saveexecutor = static_cast<ExecutorMember<orxonox::XMLPortVariableHelperClass>*>(orxonox::createExecutor(orxonox::createFunctor(orxonox::XMLPortVariableHelperClass::getSaver (variable)), std::string( #classname ) + "::" + #variable + "saver" )); \
     95    XMLPortParamGeneric(xmlcontainer##variable, classname, orxonox::XMLPortVariableHelperClass, &xmlcontainer##variable##dummy, paramname, xmlcontainer##variable##loadexecutor, xmlcontainer##variable##saveexecutor, xmlelement, mode)
     96
    7697/**
    7798    @brief This is the same as XMLPortParam, but you can set the template arguments needed to store the loadfunction.
     
    161182        ClassIdentifier<classname>::getIdentifier()->addXMLPortParamContainer(paramname, containername); \
    162183    } \
    163     containername->port((BaseObject*)this, object, xmlelement, mode)
     184    containername->port(static_cast<BaseObject*>(this), object, xmlelement, mode)
    164185
    165186// --------------------
     
    175196    @param xmlelement The XMLElement (recieved through the XMLPort function)
    176197    @param mode The mode (load/save) (received through the XMLPort function)
    177     @param bApplyLoaderMask If this is true, an added sub-object only gets loaded if it's class is included in the Loaders ClassTreeMask (this is usually false)
    178     @param bLoadBefore If this is true, the sub-cobject gets loaded (through XMLPort) BEFORE it gets added to the main class (this is usually true)
     198    @param bApplyLoaderMask If this is true, an added sub-object gets loaded only if it's class is included in the Loaders ClassTreeMask (this is usually false)
     199    @param bLoadBefore If this is true, the sub-object gets loaded (through XMLPort) BEFORE it gets added to the main class (this is usually true)
    179200
    180201    bApplyLoaderMask is usually false for the following reason:
     
    183204    Of course, if there are "standalone" weapons in the level, they wont be loaded.
    184205
    185     If bLoadBefore, an added object already has all attributes set (like it's name). This is most
     206    If bLoadBefore is true, an added object already has all attributes set (like it's name). This is most
    186207    likely the best option, so this is usually true.
    187208
     
    222243    Note that "weapons" is the subsection. This allows you to add more types of sub-objects. In our example,
    223244    you could add pilots, blinking lights or other stuff. If you don't want a subsection, just use "" (an
    224     empty string). The you can add sub-objects directly into the mainclass.
     245    empty string). Then you can add sub-objects directly into the mainclass.
    225246*/
    226247#define XMLPortObjectExtended(classname, objectclass, sectionname, loadfunction, savefunction, xmlelement, mode, bApplyLoaderMask, bLoadBefore) \
     
    329350            }
    330351
     352            ~XMLPortClassParamContainer()
     353            {
     354                assert(this->loadexecutor_);
     355                delete this->loadexecutor_;
     356                if (this->saveexecutor_)
     357                    delete this->saveexecutor_;
     358            }
     359
    331360            XMLPortParamContainer& port(BaseObject* owner, T* object, Element& xmlelement, XMLPort::Mode mode)
    332361            {
     362                OrxAssert(owner, "XMLPortParamContainer must have a BaseObject as owner.");
    333363                this->owner_ = owner;
    334364                this->parseParams_.object = object;
     
    336366                this->parseParams_.mode = mode;
    337367
    338                 if (mode == XMLPort::LoadObject)
     368                if ((mode == XMLPort::LoadObject) || (mode == XMLPort::ExpandObject))
    339369                {
    340370                    try
    341371                    {
    342                         std::string attribute = xmlelement.GetAttribute(this->paramname_);
    343                         if ((attribute.size() > 0) || (this->loadexecutor_->allDefaultValuesSet()))
     372                        if (this->owner_->lastLoadedXMLElement_ != &xmlelement)
     373                        {
     374                            this->owner_->xmlAttributes_.clear();
     375                            // Iterate through the attributes manually in order to make them case insensitive
     376                            Attribute* attribute = xmlelement.FirstAttribute(false);
     377                            while (attribute != 0)
     378                            {
     379                                this->owner_->xmlAttributes_[getLowercase(attribute->Name())] = attribute->Value();
     380                                attribute = attribute->Next(false);
     381                            }
     382                            this->owner_->lastLoadedXMLElement_ = &xmlelement;
     383                        }
     384                        std::map<std::string, std::string>::const_iterator it = this->owner_->xmlAttributes_.find(getLowercase(this->paramname_));
     385                        std::string attributeValue("");
     386                        if (it != this->owner_->xmlAttributes_.end())
     387                            attributeValue = it->second;
     388
     389                        // TODO: Checking the iterator would be better since then we can have strings with value "" as well.
     390                        //       Unfortunately this does not seem to work with the Executor parser yet.
     391                        if ((!attributeValue.empty()) || ((mode != XMLPort::ExpandObject) && this->loadexecutor_->allDefaultValuesSet()))
    344392                        {
    345393                            COUT(5) << this->owner_->getLoaderIndentation() << "Loading parameter " << this->paramname_ << " in " << this->identifier_->getName() << " (objectname " << this->owner_->getName() << ")." << std::endl << this->owner_->getLoaderIndentation();
    346                             if (this->loadexecutor_->parse(object, attribute, ","))
     394                            if (this->loadexecutor_->parse(object, attributeValue, ",") || (mode  == XMLPort::ExpandObject))
    347395                                this->parseResult_ = PR_finished;
    348396                            else
    349397                                this->parseResult_ = PR_waiting_for_default_values;
    350398                        }
     399                        else if (mode == XMLPort::ExpandObject)
     400                            this->parseResult_ = PR_finished;
    351401                        else
    352402                            this->parseResult_ = PR_waiting_for_default_values;
     
    471521            }
    472522
     523            ~XMLPortClassObjectContainer()
     524            {
     525                assert(this->loadexecutor_);
     526                delete this->loadexecutor_;
     527                if (this->saveexecutor_)
     528                    delete this->saveexecutor_;
     529            }
     530
    473531            XMLPortObjectContainer& port(T* object, Element& xmlelement, XMLPort::Mode mode)
    474532            {
    475                 if (mode == XMLPort::LoadObject)
     533                if ((mode == XMLPort::LoadObject) || (mode == XMLPort::ExpandObject))
    476534                {
    477535                    try
     
    588646            ExecutorMember<T>* saveexecutor_;
    589647    };
     648
     649
     650    // ####################################
     651    // ###  XMLPortVariableHelperClass  ###
     652    // ####################################
     653    /**
     654    @brief
     655        Helper class to load and save simple variables with XMLPort.
     656
     657        getLoader and getSaver were necessary to get the type T with
     658        the help of template function type deduction (const T& is unused).
     659        These functions return the adress of save<T> or load<T>.
     660    */
     661    class XMLPortVariableHelperClass
     662    {
     663        public:
     664            XMLPortVariableHelperClass(void* var)
     665                : variable_(var)
     666                { }
     667
     668            template <class T>
     669            void load(const T& value)
     670                { *((T*)this->variable_) = value; }
     671
     672            template <class T>
     673            const T& save()
     674                { return *((T*)this->variable_); }
     675
     676            template <class T>
     677            static void (XMLPortVariableHelperClass::*getLoader(const T& var))(const T& value)
     678                { return &XMLPortVariableHelperClass::load<T>; }
     679
     680            template <class T>
     681            static const T& (XMLPortVariableHelperClass::*getSaver(const T& var))()
     682                { return &XMLPortVariableHelperClass::save<T>; }
     683
     684        private:
     685            void* variable_;
     686    };
    590687}
    591688
  • code/trunk/src/core/input/Button.cc

    r2103 r2662  
    5959        nCommands_[1]=0;
    6060        nCommands_[2]=0;
     61        this->configContainer_ = 0;
    6162        clear();
     63    }
     64
     65    Button::~Button()
     66    {
     67        this->clear();
     68
     69        if (this->configContainer_)
     70            delete this->configContainer_;
    6271    }
    6372
  • code/trunk/src/core/input/Button.h

    r2103 r2662  
    4949    public:
    5050        Button();
    51         virtual ~Button() { clear(); }
     51        virtual ~Button();
    5252        virtual void clear();
    5353        virtual bool addParamCommand(ParamCommand* command) { return false; }
  • code/trunk/src/core/input/InputBuffer.cc

    r1755 r2662  
    7373    }
    7474
     75    InputBuffer::~InputBuffer()
     76    {
     77        for (std::list<BaseInputBufferListenerTuple*>::const_iterator it = this->listeners_.begin();
     78            it != this->listeners_.end(); ++it)
     79            delete *it;
     80    }
     81
    7582    void InputBuffer::setConfigValues()
    7683    {
  • code/trunk/src/core/input/InputBuffer.h

    r1887 r2662  
    7979        public:
    8080            InputBuffer();
     81            ~InputBuffer();
    8182            InputBuffer(const std::string allowedChars);
    8283
  • code/trunk/src/core/input/InputInterfaces.h

    r1887 r2662  
    378378        const char* const ByString[] =
    379379        {
    380             "Button0",       "Button1",       "Button2",       "Button3",
    381             "Button4",       "Button5",       "Button6",       "Button7",
    382             "Button8",       "Button9",       "Button10",      "Button11",
     380            "Button00",      "Button01",      "Button02",      "Button03",
     381            "Button04",      "Button05",      "Button06",      "Button07",
     382            "Button08",      "Button09",      "Button10",      "Button11",
    383383            "Button12",      "Button13",      "Button14",      "Button15",
    384384            "Button16",      "Button17",      "Button18",      "Button19",
     
    416416            "Slider0", "Slider1", "Slider2", "Slider3",
    417417            "Slider4", "Slider5", "Slider6", "Slider7",
    418             "Axis0",   "Axis1",   "Axis2",   "Axis3",
    419             "Axis4",   "Axis5",   "Axis6",   "Axis7",
    420             "Axis8",   "Axis9",   "Axis10",  "Axis11",
     418            "Axis00",  "Axis01",  "Axis02",  "Axis03",
     419            "Axis04",  "Axis05",  "Axis06",  "Axis07",
     420            "Axis08",  "Axis09",  "Axis10",  "Axis11",
    421421            "Axis12",  "Axis13",  "Axis14",  "Axis15"
    422422        };
  • code/trunk/src/core/input/InputManager.cc

    r2103 r2662  
    6565    SetCommandLineSwitch(keyboard_no_grab);
    6666
    67     std::string InputManager::bindingCommmandString_s = "";
    6867    EmptyHandler InputManager::EMPTY_HANDLER;
    6968    InputManager* InputManager::singletonRef_s = 0;
     
    112111        , keyDetector_(0)
    113112        , calibratorCallbackBuffer_(0)
    114         , bCalibrating_(false)
    115113        , keyboardModifiers_(0)
    116114    {
     
    119117        assert(singletonRef_s == 0);
    120118        singletonRef_s = this;
     119
     120        setConfigValues();
     121    }
     122
     123    /**
     124    @brief
     125        Sets the configurable values.
     126    */
     127    void InputManager::setConfigValues()
     128    {
     129        SetConfigValue(calibrationFilename_, "joystick_calibration.ini")
     130            .description("Ini filename for the the joy stick calibration data.")
     131            .callback(this, &InputManager::_calibrationFileCallback);
     132    }
     133
     134    /**
     135    @brief
     136        Callback for the joy stick calibration config file. @see setConfigValues.
     137    */
     138    void InputManager::_calibrationFileCallback()
     139    {
     140        ConfigFileManager::getInstance().setFilename(ConfigFileType::JoyStickCalibration, calibrationFilename_);
    121141    }
    122142
     
    174194            if (joyStickSupport)
    175195                _initialiseJoySticks();
    176             // Do this anyway to also inform everyone if a joystick was detached.
    177             _configureNumberOfJoySticks();
     196            // Do this anyway to also inform everything when a joystick was detached.
     197            _configureJoySticks();
    178198
    179199            // Set mouse/joystick region
     
    183203            // clear all buffers
    184204            _clearBuffers();
    185 
    186             // load joy stick calibration
    187             setConfigValues();
    188205
    189206            internalState_ |= OISReady;
     
    335352    /**
    336353    @brief
     354        Helper function that loads the config value vector of one coefficient
     355    */
     356    void loadCalibration(std::vector<int>& list, const std::string& sectionName, const std::string& valueName, size_t size, int defaultValue)
     357    {
     358        list.resize(size);
     359        unsigned int configValueVectorSize = ConfigFileManager::getInstance().getVectorSize(ConfigFileType::JoyStickCalibration, sectionName, valueName);
     360        if (configValueVectorSize > size)
     361            configValueVectorSize = size;
     362
     363        for (unsigned int i = 0; i < configValueVectorSize; ++i)
     364        {
     365            list[i] = omni_cast<int>(ConfigFileManager::getInstance().getValue(
     366                ConfigFileType::JoyStickCalibration, sectionName, valueName, i, omni_cast<std::string>(defaultValue), false));
     367        }
     368
     369        // fill the rest with default values
     370        for (unsigned int i = configValueVectorSize; i < size; ++i)
     371        {
     372            list[i] = defaultValue;
     373        }
     374    }
     375
     376    /**
     377    @brief
    337378        Sets the size of all the different lists that are dependent on the number
    338         of joy stick devices created.
     379        of joy stick devices created and loads the joy stick calibration.
    339380    @remarks
    340381        No matter whether there are a mouse and/or keyboard, they will always
    341382        occupy 2 places in the device number dependent lists.
    342383    */
    343     void InputManager::_configureNumberOfJoySticks()
     384    void InputManager::_configureJoySticks()
    344385    {
    345386        joySticksSize_ = joySticks_.size();
    346         devicesNum_ = 2 + joySticksSize_;
     387        devicesNum_    = 2 + joySticksSize_;
     388        joyStickIDs_         .resize(joySticksSize_);
    347389        joyStickButtonsDown_ .resize(joySticksSize_);
    348390        povStates_           .resize(joySticksSize_);
    349391        sliderStates_        .resize(joySticksSize_);
    350         joySticksCalibration_.resize(joySticksSize_);
     392        joyStickMinValues_   .resize(joySticksSize_);
     393        joyStickMaxValues_   .resize(joySticksSize_);
     394        joyStickMiddleValues_.resize(joySticksSize_);
     395        joyStickCalibrations_.resize(joySticksSize_);
    351396
    352397        for (unsigned int iJoyStick = 0; iJoyStick < joySticksSize_; iJoyStick++)
    353398        {
    354             // reset the calibration with default values
    355             for (unsigned int i = 0; i < 24; i++)
    356             {
    357                 joySticksCalibration_[iJoyStick].negativeCoeff[i] = 1.0f/32767.0f;
    358                 joySticksCalibration_[iJoyStick].positiveCoeff[i] = 1.0f/32768.0f;
    359                 joySticksCalibration_[iJoyStick].zeroStates[i] = 0;
    360             }
    361         }
     399            // Generate some sort of execution unique id per joy stick
     400            std::string id = "JoyStick_";
     401            id += omni_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Button))  + "_";
     402            id += omni_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Axis))    + "_";
     403            id += omni_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Slider))  + "_";
     404            id += omni_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_POV))     + "_";
     405            id += omni_cast<std::string>(joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Vector3)) + "_";
     406            id += joySticks_[iJoyStick]->vendor();
     407            for (unsigned int i = 0; i < iJoyStick; ++i)
     408            {
     409                if (id == joyStickIDs_[i])
     410                {
     411                    // Two joysticks are probably equal --> add the index as well
     412                    id += "_" + omni_cast<std::string>(iJoyStick);
     413                }
     414            }
     415            joyStickIDs_[iJoyStick] = id;
     416
     417            size_t axes = sliderAxes + (size_t)this->joySticks_[iJoyStick]->getNumberOfComponents(OIS::OIS_Axis);
     418            loadCalibration(joyStickMinValues_[iJoyStick], id, "MinValue", axes, -32768);
     419            loadCalibration(joyStickMaxValues_[iJoyStick], id, "MaxValue", axes,  32768);
     420            loadCalibration(joyStickMiddleValues_[iJoyStick], id, "MiddleValue", axes,      0);
     421        }
     422
     423        _evaluateCalibration();
    362424
    363425        // state management
     
    380442    }
    381443
    382     /**
    383     @brief
    384         Sets the configurable values.
    385         This mainly concerns joy stick calibrations.
    386     */
    387     void InputManager::setConfigValues()
    388     {
    389         if (joySticksSize_ > 0)
    390         {
    391             std::vector<double> coeffPos;
    392             std::vector<double> coeffNeg;
    393             std::vector<int> zero;
    394             coeffPos.resize(24);
    395             coeffNeg.resize(24);
    396             zero.resize(24);
    397             for (unsigned int i = 0; i < 24; i++)
    398             {
    399                 coeffPos[i] =  1.0f/32767.0f;
    400                 coeffNeg[i] =  1.0f/32768.0f;
    401                 zero[i]     =  0;
    402             }
    403 
    404             ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos");
    405             if (!cont)
    406             {
    407                 cont = new ConfigValueContainer(ConfigFileType::Settings, getIdentifier(), getIdentifier()->getName(), "CoeffPos", coeffPos);
    408                 getIdentifier()->addConfigValueContainer("CoeffPos", cont);
    409             }
    410             cont->getValue(&coeffPos, this);
    411 
    412             cont = getIdentifier()->getConfigValueContainer("CoeffNeg");
    413             if (!cont)
    414             {
    415                 cont = new ConfigValueContainer(ConfigFileType::Settings, getIdentifier(), getIdentifier()->getName(), "CoeffNeg", coeffNeg);
    416                 getIdentifier()->addConfigValueContainer("CoeffNeg", cont);
    417             }
    418             cont->getValue(&coeffNeg, this);
    419 
    420             cont = getIdentifier()->getConfigValueContainer("Zero");
    421             if (!cont)
    422             {
    423                 cont = new ConfigValueContainer(ConfigFileType::Settings, getIdentifier(), getIdentifier()->getName(), "Zero", zero);
    424                 getIdentifier()->addConfigValueContainer("Zero", cont);
    425             }
    426             cont->getValue(&zero, this);
    427 
    428             // copy values to our own variables
    429             for (unsigned int i = 0; i < 24; i++)
    430             {
    431                 joySticksCalibration_[0].positiveCoeff[i] = coeffPos[i];
    432                 joySticksCalibration_[0].negativeCoeff[i] = coeffNeg[i];
    433                 joySticksCalibration_[0].zeroStates[i]    = zero[i];
    434             }
    435         }
    436     }
    437 
     444    void InputManager::_evaluateCalibration()
     445    {
     446        for (unsigned int iJoyStick = 0; iJoyStick < this->joySticksSize_; ++iJoyStick)
     447        {
     448            for (unsigned int i = 0; i < this->joyStickMinValues_[iJoyStick].size(); i++)
     449            {
     450                this->joyStickCalibrations_[iJoyStick].middleValue[i] = this->joyStickMiddleValues_[iJoyStick][i];
     451                this->joyStickCalibrations_[iJoyStick].negativeCoeff[i] = - 1.0f / (this->joyStickMinValues_[iJoyStick][i] - this->joyStickMiddleValues_[iJoyStick][i]);
     452                this->joyStickCalibrations_[iJoyStick].positiveCoeff[i] =   1.0f / (this->joyStickMaxValues_[iJoyStick][i] - this->joyStickMiddleValues_[iJoyStick][i]);
     453            }
     454        }
     455    }
     456   
     457    void InputManager::_startCalibration()
     458    {
     459        for (unsigned int iJoyStick = 0; iJoyStick < this->joySticksSize_; ++iJoyStick)
     460        {
     461            // Set initial values
     462            for (unsigned int i = 0; i < this->joyStickMinValues_[iJoyStick].size(); ++i)
     463                this->joyStickMinValues_[iJoyStick][i] = INT_MAX;
     464            for (unsigned int i = 0; i < this->joyStickMaxValues_[iJoyStick].size(); ++i)
     465                this->joyStickMaxValues_[iJoyStick][i] = INT_MIN;
     466            for (unsigned int i = 0; i < this->joyStickMiddleValues_[iJoyStick].size(); ++i)
     467                this->joyStickMiddleValues_[iJoyStick][i] = 0;
     468        }
     469
     470        getInstance().internalState_ |= Calibrating;
     471        getInstance().requestEnterState("calibrator");
     472    }
     473
     474    void InputManager::_completeCalibration()
     475    {
     476        for (unsigned int iJoyStick = 0; iJoyStick < this->joySticksSize_; ++iJoyStick)
     477        {
     478            // Get the middle positions now
     479            unsigned int iAxis = 0;
     480            for (unsigned int i = 0; i < sliderAxes/2; ++i)
     481            {
     482                this->joyStickMiddleValues_[iJoyStick][iAxis++] = this->joySticks_[iJoyStick]->getJoyStickState().mSliders[i].abX;
     483                this->joyStickMiddleValues_[iJoyStick][iAxis++] = this->joySticks_[iJoyStick]->getJoyStickState().mSliders[i].abY;
     484            }
     485            // Note: joyStickMiddleValues_[iJoyStick] was already correctly resized in _configureJoySticks()
     486            assert(joySticks_[iJoyStick]->getJoyStickState().mAxes.size() == joyStickMiddleValues_[iJoyStick].size() - sliderAxes);
     487            for (unsigned int i = 0; i < joyStickMiddleValues_[iJoyStick].size() - sliderAxes; ++i)
     488            {
     489                this->joyStickMiddleValues_[iJoyStick][iAxis++] = this->joySticks_[iJoyStick]->getJoyStickState().mAxes[i].abs;
     490            }
     491
     492            for (unsigned int i = 0; i < joyStickMinValues_[iJoyStick].size(); ++i)
     493            {
     494                // Minimum values
     495                if (joyStickMinValues_[iJoyStick][i] == INT_MAX)
     496                    joyStickMinValues_[iJoyStick][i] = -32768;
     497                ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration,
     498                    this->joyStickIDs_[iJoyStick], "MinValue", i, omni_cast<std::string>(joyStickMinValues_[iJoyStick][i]), false);
     499
     500                // Maximum values
     501                if (joyStickMaxValues_[iJoyStick][i] == INT_MIN)
     502                    joyStickMaxValues_[iJoyStick][i] = 32767;
     503                ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration,
     504                    this->joyStickIDs_[iJoyStick], "MaxValue", i, omni_cast<std::string>(joyStickMaxValues_[iJoyStick][i]), false);
     505
     506                // Middle values
     507                ConfigFileManager::getInstance().setValue(ConfigFileType::JoyStickCalibration,
     508                    this->joyStickIDs_[iJoyStick], "MiddleValue", i, omni_cast<std::string>(joyStickMiddleValues_[iJoyStick][i]), false);
     509            }
     510        }
     511
     512        _evaluateCalibration();
     513
     514        // restore old input state
     515        requestLeaveState("calibrator");
     516        internalState_ &= ~Calibrating;
     517    }
    438518
    439519    // ############################################################
     
    492572            }
    493573        }
    494         singletonRef_s = 0;
     574
     575        singletonRef_s = 0;
    495576    }
    496577
     
    660741    /**
    661742    @brief
    662         Updates the InputManager. Tick is called by the Core class.
     743        Updates the states and the InputState situation.
    663744    @param dt
    664745        Delta time
     
    676757
    677758        // check for states to leave
    678         for (std::set<InputState*>::reverse_iterator rit = stateLeaveRequests_.rbegin();
    679             rit != stateLeaveRequests_.rend(); ++rit)
    680         {
    681             (*rit)->onLeave();
    682             // just to be sure that the state actually is registered
    683             assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end());
    684 
    685             activeStates_.erase((*rit)->getPriority());
    686             _updateActiveStates();
    687         }
    688         stateLeaveRequests_.clear();
     759        if (!stateLeaveRequests_.empty())
     760        {
     761            for (std::set<InputState*>::reverse_iterator rit = stateLeaveRequests_.rbegin();
     762                rit != stateLeaveRequests_.rend(); ++rit)
     763            {
     764                (*rit)->onLeave();
     765                // just to be sure that the state actually is registered
     766                assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end());
     767
     768                activeStates_.erase((*rit)->getPriority());
     769                _updateActiveStates();
     770            }
     771            stateLeaveRequests_.clear();
     772        }
    689773
    690774        // check for states to enter
    691         for (std::set<InputState*>::reverse_iterator rit = stateEnterRequests_.rbegin();
    692             rit != stateEnterRequests_.rend(); ++rit)
    693         {
    694             // just to be sure that the state actually is registered
    695             assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end());
    696 
    697             activeStates_[(*rit)->getPriority()] = (*rit);
    698             _updateActiveStates();
    699             (*rit)->onEnter();
    700         }
    701         stateEnterRequests_.clear();
     775        if (!stateEnterRequests_.empty())
     776        {
     777            for (std::set<InputState*>::reverse_iterator rit = stateEnterRequests_.rbegin();
     778                rit != stateEnterRequests_.rend(); ++rit)
     779            {
     780                // just to be sure that the state actually is registered
     781                assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end());
     782
     783                activeStates_[(*rit)->getPriority()] = (*rit);
     784                _updateActiveStates();
     785                (*rit)->onEnter();
     786            }
     787            stateEnterRequests_.clear();
     788        }
    702789
    703790        // check for states to destroy
    704         for (std::set<InputState*>::reverse_iterator rit = stateDestroyRequests_.rbegin();
    705             rit != stateDestroyRequests_.rend(); ++rit)
    706         {
    707             _destroyState((*rit));
    708         }
    709         stateDestroyRequests_.clear();
     791        if (!stateDestroyRequests_.empty())
     792        {
     793            for (std::set<InputState*>::reverse_iterator rit = stateDestroyRequests_.rbegin();
     794                rit != stateDestroyRequests_.rend(); ++rit)
     795            {
     796                _destroyState((*rit));
     797            }
     798            stateDestroyRequests_.clear();
     799        }
    710800
    711801        // check whether a state has changed its EMPTY_HANDLER situation
     
    733823            joySticks_[i]->capture();
    734824
    735         if (!bCalibrating_)
     825        if (!(internalState_ & Calibrating))
    736826        {
    737827            // call all the handlers for the held key events
     
    804894    /**
    805895    @brief
    806         Processes the accumultated data for the joy stick calibration.
    807     */
    808     void InputManager::_completeCalibration()
    809     {
    810         for (unsigned int i = 0; i < 24; i++)
    811         {
    812             // positive coefficient
    813             if (marginalsMax_[i] == INT_MIN)
    814                 marginalsMax_[i] =  32767;
    815             // coefficients
    816             if (marginalsMax_[i] - joySticksCalibration_[0].zeroStates[i])
    817             {
    818                 joySticksCalibration_[0].positiveCoeff[i]
    819                     = 1.0f/(marginalsMax_[i] - joySticksCalibration_[0].zeroStates[i]);
    820             }
    821             else
    822                 joySticksCalibration_[0].positiveCoeff[i] =  1.0f;
    823 
    824             // config value
    825             ConfigValueContainer* cont = getIdentifier()->getConfigValueContainer("CoeffPos");
    826             assert(cont);
    827             cont->set(i, joySticksCalibration_[0].positiveCoeff[i]);
    828 
    829             // negative coefficient
    830             if (marginalsMin_[i] == INT_MAX)
    831                 marginalsMin_[i] = -32768;
    832             // coefficients
    833             if (marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i])
    834             {
    835                 joySticksCalibration_[0].negativeCoeff[i] = -1.0f
    836                     / (marginalsMin_[i] - joySticksCalibration_[0].zeroStates[i]);
    837             }
    838             else
    839                 joySticksCalibration_[0].negativeCoeff[i] =  1.0f;
    840             // config value
    841             cont = getIdentifier()->getConfigValueContainer("CoeffNeg");
    842             assert(cont);
    843             cont->set(i, joySticksCalibration_[0].negativeCoeff[i]);
    844 
    845             // zero states
    846             if (i < 8)
    847             {
    848                 if (!(i & 1))
    849                     joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mSliders[i/2].abX;
    850                 else
    851                     joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mSliders[i/2].abY;
    852             }
    853             else
    854             {
    855                 if (i - 8 < joySticks_[0]->getJoyStickState().mAxes.size())
    856                     joySticksCalibration_[0].zeroStates[i] = joySticks_[0]->getJoyStickState().mAxes[i - 8].abs;
    857                 else
    858                     joySticksCalibration_[0].zeroStates[i] = 0;
    859             }
    860             // config value
    861             cont = getIdentifier()->getConfigValueContainer("Zero");
    862             assert(cont);
    863             cont->set(i, joySticksCalibration_[0].zeroStates[i]);
    864         }
    865 
    866         // restore old input state
    867         requestLeaveState("calibrator");
    868         bCalibrating_ = false;
    869     }
    870 
     896        Clears all buffers that store what keys/buttons are being pressed at the moment.
     897    */
    871898    void InputManager::clearBuffers()
    872899    {
     
    10991126    void InputManager::_fireAxis(unsigned int iJoyStick, int axis, int value)
    11001127    {
    1101         if (bCalibrating_)
    1102         {
    1103             if (value > marginalsMax_[axis])
    1104                 marginalsMax_[axis] = value;
    1105             if (value < marginalsMin_[axis])
    1106                 marginalsMin_[axis] = value;
     1128        if (internalState_ & Calibrating)
     1129        {
     1130            if (value < joyStickMinValues_[iJoyStick][axis])
     1131                joyStickMinValues_[iJoyStick][axis] = value;
     1132            if (value > joyStickMaxValues_[iJoyStick][axis])
     1133                joyStickMaxValues_[iJoyStick][axis] = value;
    11071134        }
    11081135        else
    11091136        {
    1110             float fValue = value - joySticksCalibration_[iJoyStick].zeroStates[axis];
     1137            float fValue = value - joyStickCalibrations_[iJoyStick].middleValue[axis];
    11111138            if (fValue > 0.0f)
    1112                 fValue *= joySticksCalibration_[iJoyStick].positiveCoeff[axis];
     1139                fValue *= joyStickCalibrations_[iJoyStick].positiveCoeff[axis];
    11131140            else
    1114                 fValue *= joySticksCalibration_[iJoyStick].negativeCoeff[axis];
     1141                fValue *= joyStickCalibrations_[iJoyStick].negativeCoeff[axis];
    11151142
    11161143            activeStatesTop_[2 + iJoyStick]->joyStickAxisMoved(iJoyStick, axis, fValue);
     
    11241151
    11251152        // keep in mind that the first 8 axes are reserved for the sliders
    1126         _fireAxis(iJoyStick, axis + 8, arg.state.mAxes[axis].abs);
     1153        _fireAxis(iJoyStick, axis + sliderAxes, arg.state.mAxes[axis].abs);
    11271154
    11281155        return true;
     
    13901417    void InputManager::calibrate()
    13911418    {
    1392         getInstance().bCalibrating_ = true;
    1393         getInstance().requestEnterState("calibrator");
     1419        COUT(0) << "Move all joy stick axes fully in all directions." << std::endl
     1420                << "When done, put the axex in the middle position and press enter." << std::endl;
     1421
     1422        getInstance()._startCalibration();
    13941423    }
    13951424
  • code/trunk/src/core/input/InputManager.h

    r2102 r2662  
    7171    struct JoyStickCalibration
    7272    {
    73         int zeroStates[24];
     73        int middleValue[24];
    7474        float positiveCoeff[24];
    7575        float negativeCoeff[24];
     
    136136    public: // variables
    137137        static EmptyHandler                 EMPTY_HANDLER;
     138        static const unsigned int           sliderAxes = 8;
    138139
    139140    private: // functions
     
    145146        void _initialiseMouse();
    146147        void _initialiseJoySticks();
    147         void _configureNumberOfJoySticks();
     148        void _configureJoySticks();
     149
     150        void _loadCalibration();
     151        void _startCalibration();
     152        void _completeCalibration();
     153        void _evaluateCalibration();
    148154
    149155        void _destroyKeyboard();
     
    154160
    155161        void _reload(bool joyStickSupport);
    156 
    157         void _completeCalibration();
    158162
    159163        void _fireAxis(unsigned int iJoyStick, int axis, int value);
     
    178182
    179183        void setConfigValues();
     184        void _calibrationFileCallback();
    180185
    181186    private: // variables
     
    185190        std::vector<OIS::JoyStick*>         joySticks_;            //!< OIS joy sticks
    186191        unsigned int                        joySticksSize_;
     192        std::vector<std::string>            joyStickIDs_;          //!< Execution unique identification strings for the joy sticks
    187193        unsigned int                        devicesNum_;
    188194        size_t                              windowHnd_;            //!< Render window handle
     
    192198        SimpleInputState*                   stateEmpty_;
    193199        ExtendedInputState*                 stateMaster_;          //!< Always active master input state
    194         KeyDetector*                        keyDetector_;        //!< KeyDetector instance
     200        KeyDetector*                        keyDetector_;          //!< KeyDetector instance
    195201        InputBuffer*                        calibratorCallbackBuffer_;
    196202
     
    207213
    208214        // joystick calibration
    209         //std::vector<int> marginalsMaxConfig_;
    210         //std::vector<int> marginalsMinConfig_;
    211         int                                 marginalsMax_[24];
    212         int                                 marginalsMin_[24];
    213         bool                                bCalibrated_;
    214         bool                                bCalibrating_;
     215        std::vector<std::vector<int> >      joyStickMinValues_;
     216        std::vector<std::vector<int> >      joyStickMaxValues_;
     217        std::vector<std::vector<int> >      joyStickMiddleValues_;
     218        std::vector<ConfigValueContainer*>  calibrationConfigValueContainers_;
     219        std::vector<JoyStickCalibration>    joyStickCalibrations_;
    215220
    216221        unsigned int                        keyboardModifiers_;    //!< Bit mask representing keyboard modifiers.
    217222        std::vector<POVStates>              povStates_;            //!< Keeps track of the joy stick POV states.
    218223        std::vector<SliderStates>           sliderStates_;         //!< Keeps track of the possibly two slider axes.
    219         std::vector<JoyStickCalibration>    joySticksCalibration_;
    220224
    221225        std::vector<Key>                    keysDown_;
     
    223227        std::vector<std::vector<JoyStickButtonCode::ByEnum> >  joyStickButtonsDown_;
    224228
    225         static std::string                  bindingCommmandString_s;
     229        // ConfigValues
     230        std::string                         calibrationFilename_;  //!< Joy stick calibration ini filename
     231
    226232        static InputManager*                singletonRef_s;
    227233    };
  • code/trunk/src/core/input/KeyBinder.cc

    r2103 r2662  
    3333
    3434#include "KeyBinder.h"
     35
    3536#include <fstream>
    3637#include <string>
     38
    3739#include "util/Convert.h"
    3840#include "util/Debug.h"
     
    6668            std::string keyname = KeyCode::ByString[i];
    6769            if (!keyname.empty())
    68             {
    6970                keys_[i].name_ = std::string("Key") + keyname;
    70             }
    7171            else
    72             {
    73                 // some keys have name "" because the code is not occupied by OIS
    74                 // Use "Key_" plus the number as name to put it at the end of the config file section
    75                 std::string number = convertToString(i);
    76                 if (i < 100)
    77                     number.insert(0, "0");
    78                 keys_[i].name_ = std::string("Key_") + number;
    79             }
     72                keys_[i].name_ = "";
    8073            keys_[i].paramCommandBuffer_ = &paramCommandBuffer_;
    8174            keys_[i].groupName_ = "Keys";
     
    9790        for (unsigned int i = 0; i < MouseAxisCode::numberOfAxes * 2; i++)
    9891        {
    99             mouseAxes_[i].name_ = std::string("Mouse") + MouseAxisCode::ByString[i >> 1];
     92            mouseAxes_[i].name_ = std::string("Mouse") + MouseAxisCode::ByString[i / 2];
    10093            if (i & 1)
    10194                mouseAxes_[i].name_ += "Pos";
     
    224217        allHalfAxes_.clear();
    225218
     219        // Note: Don't include the dummy keys which don't actually exist in OIS but have a number
    226220        for (unsigned int i = 0; i < KeyCode::numberOfKeys; i++)
    227             allButtons_[keys_[i].name_] = keys_ + i;
     221            if (!keys_[i].name_.empty())
     222                allButtons_[keys_[i].name_] = keys_ + i;
    228223        for (unsigned int i = 0; i < numberOfMouseButtons_; i++)
    229224            allButtons_[mouseButtons_[i].name_] = mouseButtons_ + i;
     
    327322        if (bDeriveMouseInput_)
    328323        {
    329             // only update when derive dt has passed
     324            // only update when derivation dt has passed
    330325            if (deriveTime_ > derivePeriod_)
    331326            {
    332327                for (int i = 0; i < 2; i++)
    333328                {
    334                     if (mouseRelative_[i] > 0)
     329                    if (mouseRelative_[i] < 0)
    335330                    {
    336331                        mouseAxes_[2*i + 0].absVal_
    337                             =  mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_;
     332                            = -mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_;
    338333                        mouseAxes_[2*i + 1].absVal_ = 0.0f;
    339334                    }
    340                     else if (mouseRelative_[i] < 0)
     335                    else if (mouseRelative_[i] > 0)
    341336                    {
    342337                        mouseAxes_[2*i + 0].absVal_ = 0.0f;
    343338                        mouseAxes_[2*i + 1].absVal_
    344                             = -mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_;
     339                            =  mouseRelative_[i] / deriveTime_ * 0.0005 * mouseSensitivityDerived_;
    345340                    }
    346341                    else
     
    363358            // Why dividing relative value by dt? The reason lies in the simple fact, that when you
    364359            // press a button that has relative movement, that value has to be multiplied by dt to be
    365             // frame rate independant. This can easily (and only) be done in tickInput(float).
     360            // frame rate independent. This can easily (and only) be done in tickInput(float).
    366361            // Hence we need to divide by dt here for the mouse to compensate, because the relative
    367362            // move movements have nothing to do with dt.
     
    441436            for (int i = 0; i < 2; i++)
    442437            {
    443                 if (rel[i]) // performance opt. if rel[i] == 0
     438                if (rel[i]) // performance opt. for the case that rel[i] == 0
    444439                {
    445440                    // write absolute values
     
    454449                        mousePosition_[i] = -mouseClippingSize_;
    455450
    456                     if (mousePosition_[i] >= 0)
     451                    if (mousePosition_[i] < 0)
    457452                    {
    458                         mouseAxes_[2*i + 0].absVal_ =   mousePosition_[i]/(float)mouseClippingSize_ * mouseSensitivity_;
     453                        mouseAxes_[2*i + 0].absVal_ =  -mousePosition_[i]/(float)mouseClippingSize_ * mouseSensitivity_;
    459454                        mouseAxes_[2*i + 1].absVal_ =  0.0f;
    460455                    }
     
    462457                    {
    463458                        mouseAxes_[2*i + 0].absVal_ =  0.0f;
    464                         mouseAxes_[2*i + 1].absVal_ =  -mousePosition_[i]/(float)mouseClippingSize_ * mouseSensitivity_;
     459                        mouseAxes_[2*i + 1].absVal_ =   mousePosition_[i]/(float)mouseClippingSize_ * mouseSensitivity_;
    465460                    }
    466461                }
     
    471466        for (int i = 0; i < 2; i++)
    472467        {
    473             if (rel[i] > 0)
    474                 mouseAxes_[0 + 2*i].relVal_ =  ((float)rel[i])/(float)mouseClippingSize_ * mouseSensitivity_;
     468            if (rel[i] < 0)
     469                mouseAxes_[0 + 2*i].relVal_ = -((float)rel[i])/(float)mouseClippingSize_ * mouseSensitivity_;
    475470            else
    476                 mouseAxes_[1 + 2*i].relVal_ = -((float)rel[i])/(float)mouseClippingSize_ * mouseSensitivity_;
     471                mouseAxes_[1 + 2*i].relVal_ =  ((float)rel[i])/(float)mouseClippingSize_ * mouseSensitivity_;
    477472        }
    478473    }
     
    484479    void KeyBinder::mouseScrolled(int abs, int rel)
    485480    {
    486         if (rel > 0)
    487             for (int i = 0; i < rel/mouseWheelStepSize_; i++)
     481        if (rel < 0)
     482            for (int i = 0; i < -rel/mouseWheelStepSize_; i++)
    488483                mouseButtons_[8].execute(KeybindMode::OnPress, ((float)abs)/mouseWheelStepSize_);
    489484        else
    490             for (int i = 0; i < -rel/mouseWheelStepSize_; i++)
     485            for (int i = 0; i < rel/mouseWheelStepSize_; i++)
    491486                mouseButtons_[9].execute(KeybindMode::OnPress, ((float)abs)/mouseWheelStepSize_);
    492487    }
     
    495490    {
    496491        int i = axis * 2;
    497         if (value >= 0)
    498         {
    499             joyStickAxes_[joyStickID][i].absVal_ = value;
    500             joyStickAxes_[joyStickID][i].relVal_ = value;
     492        if (value < 0)
     493        {
     494            joyStickAxes_[joyStickID][i].absVal_ = -value;
     495            joyStickAxes_[joyStickID][i].relVal_ = -value;
    501496            joyStickAxes_[joyStickID][i].hasChanged_ = true;
    502497            if (joyStickAxes_[joyStickID][i + 1].absVal_ > 0.0f)
     
    509504        else
    510505        {
    511             joyStickAxes_[joyStickID][i + 1].absVal_ = -value;
    512             joyStickAxes_[joyStickID][i + 1].relVal_ = -value;
     506            joyStickAxes_[joyStickID][i + 1].absVal_ = value;
     507            joyStickAxes_[joyStickID][i + 1].relVal_ = value;
    513508            joyStickAxes_[joyStickID][i + 1].hasChanged_ = true;
    514509            if (joyStickAxes_[joyStickID][i].absVal_ > 0.0f)
  • code/trunk/src/core/input/KeyBinder.h

    r2103 r2662  
    3939
    4040#include <vector>
     41#include <cassert>
     42
    4143#include "InputInterfaces.h"
    4244#include "Button.h"
     
    4446#include "InputCommands.h"
    4547#include "JoyStickDeviceNumberListener.h"
    46 #include "core/ConfigFileManager.h"
    4748
    4849namespace orxonox
     
    171172
    172173    inline void KeyBinder::keyPressed (const KeyEvent& evt)
    173     { keys_[evt.key].execute(KeybindMode::OnPress); }
     174    { assert(!keys_[evt.key].name_.empty()); keys_[evt.key].execute(KeybindMode::OnPress); }
    174175
    175176    inline void KeyBinder::keyReleased(const KeyEvent& evt)
    176     { keys_[evt.key].execute(KeybindMode::OnRelease); }
     177    { assert(!keys_[evt.key].name_.empty()); keys_[evt.key].execute(KeybindMode::OnRelease); }
    177178
    178179    inline void KeyBinder::keyHeld    (const KeyEvent& evt)
    179     { keys_[evt.key].execute(KeybindMode::OnHold); }
     180    { assert(!keys_[evt.key].name_.empty()); keys_[evt.key].execute(KeybindMode::OnHold); }
    180181
    181182
Note: See TracChangeset for help on using the changeset viewer.