Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 12, 2009, 8:20:07 PM (15 years ago)
Author:
rgrieder
Message:

Merged core5 branch back to the trunk.
Key features include clean level unloading and an extended XML event system.

Two important notes:
Delete your keybindings.ini files! * or you will still get parser errors when loading the key bindings.
Delete build_dir/lib/modules/libgamestates.module! * or orxonox won't start.
Best thing to do is to delete the build folder ;)

Location:
code/trunk
Files:
13 edited
2 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/input/Button.cc

    r5781 r5929  
    170170
    171171                // evaluate the command
    172                 CommandEvaluation eval = CommandExecutor::evaluate(commandStr);
     172                const CommandEvaluation& eval = CommandExecutor::evaluate(commandStr);
    173173                if (!eval.isValid())
    174174                {
    175                     parseError("Command evaluation failed.", true);
     175                    parseError("Command evaluation of \"" + commandStr + "\"failed.", true);
    176176                    continue;
    177177                }
  • code/trunk/src/libraries/core/input/CMakeLists.txt

    r5781 r5929  
    99  JoyStickQuantityListener.cc
    1010  KeyBinder.cc
     11  KeyBinderManager.cc
    1112  Keyboard.cc
    1213  KeyDetector.cc
  • code/trunk/src/libraries/core/input/InputDevice.h

    r5781 r5929  
    4141#include <ois/OISInputManager.h>
    4242
     43#include "util/Clock.h"
    4344#include "util/Debug.h"
    4445#include "util/Exception.h"
    45 #include "core/Clock.h"
    4646#include "InputState.h"
    4747
  • code/trunk/src/libraries/core/input/InputManager.cc

    r5781 r5929  
    4141#include <boost/foreach.hpp>
    4242
     43#include "util/Clock.h"
    4344#include "util/Convert.h"
    4445#include "util/Exception.h"
    4546#include "util/ScopeGuard.h"
    46 #include "core/Clock.h"
    4747#include "core/CoreIncludes.h"
    4848#include "core/ConfigValueIncludes.h"
     
    5353
    5454#include "InputBuffer.h"
    55 #include "KeyDetector.h"
    5655#include "JoyStick.h"
    5756#include "JoyStickQuantityListener.h"
     
    8887        , oisInputManager_(0)
    8988        , devices_(2)
    90         , bExclusiveMouse_(false)
     89        , mouseMode_(MouseMode::Nonexclusive)
    9190        , emptyState_(0)
    92         , keyDetector_(0)
    9391        , calibratorCallbackHandler_(0)
    9492    {
     
    9997        this->setConfigValues();
    10098
     99        if (GraphicsManager::getInstance().isFullScreen())
     100            mouseMode_ = MouseMode::Exclusive;
    101101        this->loadDevices();
    102102
     
    105105        emptyState_->setHandler(&InputHandler::EMPTY);
    106106        activeStates_[emptyState_->getPriority()] = emptyState_;
    107 
    108         // KeyDetector to evaluate a pressed key's name
    109         InputState* detector = createInputState("detector", false, false, InputStatePriority::Detector);
    110         // Create a callback to avoid buttonHeld events after the key has been detected
    111         FunctorMember<InputManager>* bufferFunctor = createFunctor(&InputManager::clearBuffers);
    112         bufferFunctor->setObject(this);
    113         detector->setLeaveFunctor(bufferFunctor);
    114         keyDetector_ = new KeyDetector();
    115         detector->setHandler(keyDetector_);
    116107
    117108        // Joy stick calibration helper callback
     
    124115        this->updateActiveStates();
    125116
    126         {
    127             // calibrate console command
    128             FunctorMember<InputManager>* functor = createFunctor(&InputManager::calibrate);
    129             functor->setObject(this);
    130             this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "calibrate"), true);
    131         }
    132         {
    133             // reload console command
    134             FunctorMember<InputManager>* functor = createFunctor(&InputManager::reload);
    135             functor->setObject(this);
    136             this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "reload"), false);
    137         }
     117        // calibrate console command
     118        this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&InputManager::calibrate, this), "calibrate"), true);
     119        // reload console command
     120        this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&InputManager::reload, this), "reload"), false);
    138121
    139122        CCOUT(4) << "Construction complete." << std::endl;
     
    172155        paramList.insert(std::make_pair("w32_keyboard", "DISCL_FOREGROUND"));
    173156        paramList.insert(std::make_pair("w32_mouse", "DISCL_FOREGROUND"));
    174         if (bExclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
     157        if (mouseMode_ == MouseMode::Exclusive || GraphicsManager::getInstance().isFullScreen())
    175158        {
    176159            // Disable Windows key plus special keys (like play, stop, next, etc.)
     
    185168        paramList.insert(std::make_pair("XAutoRepeatOn", "true"));
    186169
    187         if (bExclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
     170        if (mouseMode_ == MouseMode::Exclusive || GraphicsManager::getInstance().isFullScreen())
    188171        {
    189172            if (CommandLine::getValue("keyboard_no_grab").getBool())
     
    274257    }
    275258
    276     void InputManager::setKeyDetectorCallback(const std::string& command)
    277     {
    278         this->keyDetector_->setCallbackCommand(command);
    279     }
    280 
    281259    // ############################################################
    282260    // #####                    Destruction                   #####
     
    289267
    290268        // Destroy calibrator helper handler and state
    291         delete keyDetector_;
    292269        this->destroyState("calibrator");
    293270        // Destroy KeyDetector and state
    294         delete calibratorCallbackHandler_;
    295         this->destroyState("detector");
     271        calibratorCallbackHandler_->destroy();
    296272        // destroy the empty InputState
    297273        this->destroyStateInternal(this->emptyState_);
     
    528504
    529505        // Check whether we have to change the mouse mode
     506        MouseMode::Value requestedMode = MouseMode::Dontcare;
    530507        std::vector<InputState*>& mouseStates = devices_[InputDeviceEnumerator::Mouse]->getStateListRef();
    531         if (mouseStates.empty() && bExclusiveMouse_ ||
    532             !mouseStates.empty() && mouseStates.front()->getIsExclusiveMouse() != bExclusiveMouse_)
    533         {
    534             bExclusiveMouse_ = !bExclusiveMouse_;
     508        if (mouseStates.empty())
     509            requestedMode = MouseMode::Nonexclusive;
     510        else
     511            requestedMode = mouseStates.front()->getMouseMode();
     512        if (requestedMode != MouseMode::Dontcare && mouseMode_ != requestedMode)
     513        {
     514            mouseMode_ = requestedMode;
    535515            if (!GraphicsManager::getInstance().isFullScreen())
    536516                this->reloadInternal();
     
    722702        }
    723703        statesByName_.erase(state->getName());
    724         delete state;
     704        state->destroy();
    725705    }
    726706}
  • code/trunk/src/libraries/core/input/InputManager.h

    r5781 r5929  
    161161        // Various getters and setters
    162162        //-------------------------------
    163         //! Sets the the name of the command used by the KeyDetector as callback.
    164         void setKeyDetectorCallback(const std::string& command);
    165163        //! Returns the number of joy stick that have been created since the c'tor or last call to reload().
    166164        unsigned int getJoyStickQuantity() const
     
    193191        OIS::InputManager*                  oisInputManager_;      //!< OIS input manager
    194192        std::vector<InputDevice*>           devices_;              //!< List of all input devices (keyboard, mouse, joy sticks)
    195         bool                                bExclusiveMouse_;      //!< Currently applied mouse mode
     193        MouseMode::Value                    mouseMode_;            //!< Currently applied mouse mode
    196194
    197195        // some internally handled states and handlers
    198196        InputState*                         emptyState_;           //!< Lowest priority states (makes handling easier)
    199         KeyDetector*                        keyDetector_;          //!< KeyDetector instance
    200197        //! InputBuffer that reacts to the Enter key when calibrating the joy sticks
    201198        InputBuffer*                        calibratorCallbackHandler_;
  • code/trunk/src/libraries/core/input/InputState.cc

    r5781 r5929  
    3737        , bAlwaysGetsInput_(bAlwaysGetsInput)
    3838        , bTransparent_(bTransparent)
    39         , bExclusiveMouse_(true)
     39        , mouseMode_(MouseMode::Dontcare)
    4040        , bExpired_(true)
    4141        , handlers_(2)
  • code/trunk/src/libraries/core/input/InputState.h

    r5781 r5929  
    5555        static const int Detector     = HighPriority + 2;
    5656    };
     57
     58    namespace MouseMode
     59    {
     60        enum Value
     61        {
     62            Exclusive,
     63            Nonexclusive,
     64            Dontcare
     65        };
     66    }
    5767
    5868    /**
     
    120130        void setHandler        (InputHandler* handler);
    121131
    122         void setIsExclusiveMouse(bool value) { bExclusiveMouse_ = value; this->bExpired_ = true; }
    123         bool getIsExclusiveMouse() const { return bExclusiveMouse_; }
     132        void setMouseMode(MouseMode::Value value) { mouseMode_ = value; this->bExpired_ = true; }
     133        MouseMode::Value getMouseMode() const { return mouseMode_; }
    124134
    125135        //! Returns the name of the state (which is unique!)
     
    174184        const bool                  bAlwaysGetsInput_;      //!< See class declaration for explanation
    175185        const bool                  bTransparent_;          //!< See class declaration for explanation
    176         bool                        bExclusiveMouse_;       //!< See class declaration for explanation
     186        MouseMode::Value            mouseMode_;             //!< See class declaration for explanation
    177187        int                         priority_;              //!< Current priority (might change)
    178188        bool                        bExpired_;              //!< See hasExpired()
  • code/trunk/src/libraries/core/input/KeyBinder.cc

    r5781 r5929  
    2727 */
    2828
    29 /**
    30  @file
    31  @brief Implementation of the different input handlers.
    32  */
    33 
    3429#include "KeyBinder.h"
    3530
    3631#include "util/Convert.h"
    3732#include "util/Debug.h"
     33#include "util/Exception.h"
    3834#include "core/ConfigValueIncludes.h"
    3935#include "core/CoreIncludes.h"
     
    4844        Constructor that does as little as necessary.
    4945    */
    50     KeyBinder::KeyBinder()
     46    KeyBinder::KeyBinder(const std::string& filename)
    5147        : deriveTime_(0.0f)
     48        , filename_(filename)
    5249    {
    5350        mouseRelative_[0] = 0;
     
    103100        // set them here to use allHalfAxes_
    104101        setConfigValues();
     102
     103        // Load the bindings if filename was given
     104        if (!this->filename_.empty())
     105            this->loadBindings();
    105106    }
    106107
     
    240241    @brief
    241242        Loads the key and button bindings.
    242     @return
    243         True if loading succeeded.
    244     */
    245     void KeyBinder::loadBindings(const std::string& filename)
     243    */
     244    void KeyBinder::loadBindings()
    246245    {
    247246        COUT(3) << "KeyBinder: Loading key bindings..." << std::endl;
    248247
    249         if (filename.empty())
    250             return;
    251 
    252         if (this->configFile_ == ConfigFileType::NoType)
    253         {
    254             // Get a new ConfigFileType from the ConfigFileManager
    255             this->configFile_ = ConfigFileManager::getInstance().getNewConfigFileType();
    256         }
    257 
    258         ConfigFileManager::getInstance().setFilename(this->configFile_, filename);
     248        // Get a new ConfigFileType from the ConfigFileManager
     249        this->configFile_ = ConfigFileManager::getInstance().getNewConfigFileType();
     250
     251        ConfigFileManager::getInstance().setFilename(this->configFile_, this->filename_);
    259252
    260253        // Parse bindings and create the ConfigValueContainers if necessary
    261         clearBindings();
    262254        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
    263255            it->second->readConfigValue(this->configFile_);
  • code/trunk/src/libraries/core/input/KeyBinder.h

    r5781 r5929  
    2626 *
    2727 */
    28 
    29 /**
    30 @file
    31 @brief
    32     Different definitions of input processing.
    33 */
    3428
    3529#ifndef _KeyBinder_H__
     
    5347    /**
    5448    @brief
    55         Handles mouse, keyboard and joy stick input while in the actual game mode.
    56         Manages the key bindings.
     49        Maps mouse, keyboard and joy stick input to command strings and executes them.
     50
     51        The bindings are stored in ini-files (like the one for configValues) in the config Path.
     52    @remarks
     53        You cannot change the filename because the KeyBinderManager maps these filenames to the
     54        KeyBinders. If you need to load other bindings, just create a new one.
    5755    */
    5856    class _CoreExport KeyBinder : public InputHandler, public JoyStickQuantityListener
    5957    {
    6058    public:
    61         KeyBinder ();
     59        KeyBinder (const std::string& filename);
    6260        virtual ~KeyBinder();
    6361
    64         void loadBindings(const std::string& filename);
    6562        void clearBindings();
    6663        bool setBinding(const std::string& binding, const std::string& name, bool bTemporary = false);
     64        const std::string& getBindingsFilename()
     65            { return this->filename_; }
    6766        void setConfigValues();
    6867        void resetJoyStickAxes();
    6968
    7069    protected: // functions
     70        void loadBindings();
     71        void buttonThresholdChanged();
     72        void initialiseJoyStickBindings();
     73        void compilePointerLists();
     74        // from JoyStickQuantityListener interface
     75        virtual void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);
     76
    7177        void allDevicesUpdated(float dt);
    7278        void mouseUpdated(float dt);
     
    7480        // internal
    7581        void tickHalfAxis(HalfAxis& halfAxis);
    76 
    77         void buttonThresholdChanged();
    78         // from JoyStickQuantityListener interface
    79         virtual void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);
    80         void initialiseJoyStickBindings();
    81         void compilePointerLists();
    8282
    8383        void buttonPressed (const KeyEvent& evt);
     
    144144        float deriveTime_;
    145145
     146        //! Name of the file used in this KeyBinder (constant!)
     147        const std::string filename_;
    146148        //! Config file used. ConfigFileType::NoType in case of KeyDetector. Also indicates whether we've already loaded.
    147149        ConfigFileType configFile_;
     
    171173    };
    172174
     175
    173176    inline void KeyBinder::buttonPressed (const KeyEvent& evt)
    174177    { assert(!keys_[evt.getKeyCode()].name_.empty()); keys_[evt.getKeyCode()].execute(KeybindMode::OnPress); }
  • code/trunk/src/libraries/core/input/KeyDetector.cc

    r5781 r5929  
    2929#include "KeyDetector.h"
    3030
    31 #include "util/Debug.h"
     31#include "core/ConsoleCommand.h"
    3232#include "core/CoreIncludes.h"
     33#include "core/ScopedSingletonManager.h"
    3334#include "Button.h"
     35#include "InputManager.h"
     36#include "InputState.h"
    3437
    3538namespace orxonox
    3639{
    37     /**
    38     @brief
    39         Constructor
    40     */
     40    std::string KeyDetector::callbackCommand_s = "KeyDetectorKeyPressed";
     41    KeyDetector* KeyDetector::singletonPtr_s = 0;
     42    ManageScopedSingleton(KeyDetector, ScopeID::Graphics, false);
     43
    4144    KeyDetector::KeyDetector()
     45        : KeyBinder("")
    4246    {
    4347        RegisterObject(KeyDetector);
     48
     49        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&KeyDetector::callback,  this), callbackCommand_s));
     50        this->assignCommands();
     51
     52        inputState_ = InputManager::getInstance().createInputState("detector", false, false, InputStatePriority::Detector);
     53        // Create a callback to avoid buttonHeld events after the key has been detected
     54        inputState_->setLeaveFunctor(createFunctor(&InputManager::clearBuffers, &InputManager::getInstance()));
     55        inputState_->setHandler(this);
    4456    }
    4557
    46     /**
    47     @brief
    48         Destructor
    49     */
    5058    KeyDetector::~KeyDetector()
    5159    {
     60        inputState_->setHandler(NULL);
     61        InputManager::getInstance().destroyState("detector");
    5262    }
    5363
    54     /**
    55     @brief
    56         Assigns all the buttons 'command' plus the button's name.
    57     */
    58     void KeyDetector::setCallbackCommand(const std::string& command)
     64    void KeyDetector::assignCommands()
    5965    {
    60         callbackCommand_ = command;
     66        // Assign every button/axis the same command, but with its name as argument
    6167        clearBindings();
    6268        for (std::map<std::string, Button*>::const_iterator it = allButtons_.begin(); it != allButtons_.end(); ++it)
    6369        {
    64             it->second->bindingString_ = callbackCommand_ + it->second->groupName_ + "." + it->second->name_;
     70            it->second->bindingString_ = callbackCommand_s + " " + it->second->groupName_ + "." + it->second->name_;
    6571            it->second->parse();
    6672        }
     73    }
     74
     75    void KeyDetector::callback(const std::string& name)
     76    {
     77        // Call the registered function
     78        if (this->callbackFunction_)
     79            (*this->callbackFunction_)(name);
    6780    }
    6881
     
    7083    {
    7184        KeyBinder::JoyStickQuantityChanged(joyStickList);
    72         if (!callbackCommand_.empty())
    73             setCallbackCommand(callbackCommand_);
     85        this->assignCommands();
    7486    }
    7587}
  • code/trunk/src/libraries/core/input/KeyDetector.h

    r5781 r5929  
    3232#include "InputPrereqs.h"
    3333
    34 #include <string>
     34#include "util/Singleton.h"
    3535#include "KeyBinder.h"
    3636
    3737namespace orxonox
    3838{
    39     class _CoreExport KeyDetector : public KeyBinder
     39    class _CoreExport KeyDetector : public KeyBinder, public Singleton<KeyDetector>
    4040    {
     41        friend class Singleton<KeyDetector>;
     42
    4143    public:
    4244        KeyDetector();
    4345        ~KeyDetector();
    44         void setCallbackCommand(const std::string& command);
    45         void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);
     46
     47        void setCallback(Functor* function) { this->callbackFunction_ = function; }
    4648
    4749    private:
    48         std::string callbackCommand_;
     50        KeyDetector(const KeyDetector&);
     51
     52        void callback(const std::string& name);
     53        void JoyStickQuantityChanged(const std::vector<JoyStick*>& joyStickList);
     54        void assignCommands();
     55
     56        Functor* callbackFunction_;
     57        InputState* inputState_;
     58        static std::string callbackCommand_s;
     59        static KeyDetector* singletonPtr_s;
    4960    };
    5061}
  • code/trunk/src/libraries/core/input/Mouse.cc

    r5781 r5929  
    4848
    4949#ifdef ORXONOX_PLATFORM_LINUX
    50         {
    51             // Mouse grab console command
    52             FunctorMember<Mouse>* functor = createFunctor(&Mouse::grab);
    53             functor->setObject(this);
    54             this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "grab"), false);
    55         }
    56         {
    57             // Mouse ungrab console command
    58             FunctorMember<Mouse>* functor = createFunctor(&Mouse::ungrab);
    59             functor->setObject(this);
    60             this->getIdentifier()->addConsoleCommand(createConsoleCommand(functor, "ungrab"), false);
    61         }
     50        // Mouse grab console command
     51        this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&Mouse::grab, this), "grab"), false);
     52        // Mouse ungrab console command
     53        this->getIdentifier()->addConsoleCommand(createConsoleCommand(createFunctor(&Mouse::ungrab, this), "ungrab"), false);
    6254#endif
    6355    }
Note: See TracChangeset for help on using the changeset viewer.