Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 30, 2009, 2:22:00 AM (15 years ago)
Author:
rgrieder
Message:

Merged resource2 branch back to trunk.

IMPORTANT NOTE:
Upon this merge you need to specifically call your data directory "data_extern" when checking it out (when you don't provide a name, it will be just called 'trunk').
The new CMake variable is EXTERNAL_DATA_DIRECTORY. DATA_DIRECTORY now points to the one the source part of the repository.
UPDATE YOUR DATA DIRECTORY AS WELL!!!

Location:
code/trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

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

    r3327 r5695  
    5959        nCommands_[1]=0;
    6060        nCommands_[2]=0;
    61         this->configContainer_ = 0;
    6261    }
    6362
  • code/trunk/src/core/input/InputManager.cc

    r3370 r5695  
    4141#include <boost/foreach.hpp>
    4242
     43#include "util/Convert.h"
    4344#include "util/Exception.h"
    4445#include "util/ScopeGuard.h"
     
    4950#include "core/CommandLine.h"
    5051#include "core/Functor.h"
     52#include "core/GraphicsManager.h"
    5153
    5254#include "InputBuffer.h"
     
    8284    // ##########                                        ##########
    8385    // ############################################################
    84     InputManager::InputManager(size_t windowHnd)
     86    InputManager::InputManager()
    8587        : internalState_(Bad)
    8688        , oisInputManager_(0)
    8789        , devices_(2)
    88         , windowHnd_(0)
     90        , bExclusiveMouse_(false)
    8991        , emptyState_(0)
    9092        , keyDetector_(0)
     
    9799        this->setConfigValues();
    98100
    99         this->loadDevices(windowHnd);
     101        this->loadDevices();
    100102
    101103        // Lowest priority empty InputState
     
    147149        Creates the OIS::InputMananger, the keyboard, the mouse and
    148150        the joys ticks. If either of the first two fail, this method throws an exception.
    149     @param windowHnd
    150         The window handle of the render window
    151151    @param windowWidth
    152152        The width of the render window
     
    154154        The height of the render window
    155155    */
    156     void InputManager::loadDevices(size_t windowHnd)
    157     {
    158         CCOUT(3) << "Loading input devices..." << std::endl;
     156    void InputManager::loadDevices()
     157    {
     158        CCOUT(4) << "Loading input devices..." << std::endl;
    159159
    160160        // When loading the devices they should not already be loaded
     
    164164        assert(devices_.size() == InputDeviceEnumerator::FirstJoyStick);
    165165
    166         // store handle internally so we can reload OIS
    167         windowHnd_ = windowHnd;
    168 
     166        // Fill parameter list
    169167        OIS::ParamList paramList;
    170         std::ostringstream windowHndStr;
    171 
    172         // Fill parameter list
    173         windowHndStr << static_cast<unsigned int>(windowHnd);
    174         paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
     168        size_t windowHnd = GraphicsManager::getInstance().getRenderWindowHandle();
     169        paramList.insert(std::make_pair("WINDOW", multi_cast<std::string>(windowHnd)));
    175170#if defined(ORXONOX_PLATFORM_WINDOWS)
    176         //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_NONEXCLUSIVE")));
    177         //paramList.insert(std::make_pair(std::string("w32_mouse"), std::string("DISCL_FOREGROUND")));
    178         //paramList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_NONEXCLUSIVE")));
    179         //paramList.insert(std::make_pair(std::string("w32_keyboard"), std::string("DISCL_FOREGROUND")));
     171        paramList.insert(std::make_pair("w32_keyboard", "DISCL_NONEXCLUSIVE"));
     172        paramList.insert(std::make_pair("w32_keyboard", "DISCL_FOREGROUND"));
     173        paramList.insert(std::make_pair("w32_mouse", "DISCL_FOREGROUND"));
     174        if (bExclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
     175        {
     176            // Disable Windows key plus special keys (like play, stop, next, etc.)
     177            paramList.insert(std::make_pair("w32_keyboard", "DISCL_NOWINKEY"));
     178            paramList.insert(std::make_pair("w32_mouse", "DISCL_EXCLUSIVE"));
     179        }
     180        else
     181            paramList.insert(std::make_pair("w32_mouse", "DISCL_NONEXCLUSIVE"));
    180182#elif defined(ORXONOX_PLATFORM_LINUX)
    181         paramList.insert(std::make_pair(std::string("XAutoRepeatOn"), std::string("true")));
    182         paramList.insert(std::make_pair(std::string("x11_mouse_grab"), "true"));
    183         paramList.insert(std::make_pair(std::string("x11_mouse_hide"), "true"));
    184         bool kbNoGrab;
    185         CommandLine::getValue("keyboard_no_grab", &kbNoGrab);
    186         if (kbNoGrab)
    187             paramList.insert(std::make_pair(std::string("x11_keyboard_grab"), std::string("false")));
     183        // Enabling this is probably a bad idea, but whenever orxonox crashes, the setting stays on
     184        // Trouble might be that the Pressed event occurs a bit too often...
     185        paramList.insert(std::make_pair("XAutoRepeatOn", "true"));
     186
     187        if (bExclusiveMouse_ || GraphicsManager::getInstance().isFullScreen())
     188        {
     189            if (CommandLine::getValue("keyboard_no_grab").getBool())
     190                paramList.insert(std::make_pair("x11_keyboard_grab", "false"));
     191            else
     192                paramList.insert(std::make_pair("x11_keyboard_grab", "true"));
     193            paramList.insert(std::make_pair("x11_mouse_grab",  "true"));
     194            paramList.insert(std::make_pair("x11_mouse_hide", "true"));
     195        }
    188196        else
    189             paramList.insert(std::make_pair(std::string("x11_keyboard_grab"), std::string("true")));
     197        {
     198            paramList.insert(std::make_pair("x11_keyboard_grab", "false"));
     199            paramList.insert(std::make_pair("x11_mouse_grab",  "false"));
     200            paramList.insert(std::make_pair("x11_mouse_hide", "false"));
     201        }
    190202#endif
    191203
     
    212224        }
    213225
    214         // TODO: Remove the two parameters
    215226        this->loadMouse();
    216227        this->loadJoySticks();
     
    219230        this->updateActiveStates();
    220231
    221         CCOUT(3) << "Input devices loaded." << std::endl;
     232        CCOUT(4) << "Input devices loaded." << std::endl;
    222233    }
    223234
     
    275286    InputManager::~InputManager()
    276287    {
    277         CCOUT(4) << "Destroying..." << std::endl;
     288        CCOUT(3) << "Destroying..." << std::endl;
    278289
    279290        // Destroy calibrator helper handler and state
     
    293304            this->destroyDevices();
    294305
    295         CCOUT(4) << "Destruction complete." << std::endl;
     306        CCOUT(3) << "Destruction complete." << std::endl;
    296307    }
    297308
     
    304315    void InputManager::destroyDevices()
    305316    {
    306         CCOUT(3) << "Destroying devices..." << std::endl;
     317        CCOUT(4) << "Destroying devices..." << std::endl;
    307318
    308319        BOOST_FOREACH(InputDevice*& device, devices_)
     
    336347
    337348        internalState_ |= Bad;
    338         CCOUT(3) << "Destroyed devices." << std::endl;
     349        CCOUT(4) << "Destroyed devices." << std::endl;
    339350    }
    340351
     
    365376
    366377        this->destroyDevices();
    367         this->loadDevices(windowHnd_);
     378        this->loadDevices();
    368379
    369380        internalState_ &= ~Bad;
    370381        internalState_ &= ~ReloadRequest;
    371         CCOUT(3) << "Reloading complete." << std::endl;
     382        CCOUT(4) << "Reloading complete." << std::endl;
    372383    }
    373384
     
    481492    void InputManager::updateActiveStates()
    482493    {
     494        assert((internalState_ & InputManager::Ticking) == 0);
    483495        // temporary resize
    484496        for (unsigned int i = 0; i < devices_.size(); ++i)
     
    512524        for (std::set<InputState*>::const_iterator it = tempSet.begin();it != tempSet.end(); ++it)
    513525            activeStatesTicked_.push_back(*it);
     526
     527        // Check whether we have to change the mouse mode
     528        std::vector<InputState*>& mouseStates = devices_[InputDeviceEnumerator::Mouse]->getStateListRef();
     529        if (mouseStates.empty() && bExclusiveMouse_ ||
     530            !mouseStates.empty() && mouseStates.front()->getIsExclusiveMouse() != bExclusiveMouse_)
     531        {
     532            bExclusiveMouse_ = !bExclusiveMouse_;
     533            if (!GraphicsManager::getInstance().isFullScreen())
     534                this->reloadInternal();
     535        }
    514536    }
    515537
     
    556578    }
    557579
    558     // ############################################################
    559     // #####                    Iput States                   #####
     580    std::pair<int, int> InputManager::getMousePosition() const
     581    {
     582        Mouse* mouse = static_cast<Mouse*>(devices_[InputDeviceEnumerator::Mouse]);
     583        if (mouse != NULL)
     584        {
     585            const OIS::MouseState state = mouse->getOISDevice()->getMouseState();
     586            return std::make_pair(state.X.abs, state.Y.abs);
     587        }
     588        else
     589            return std::make_pair(0, 0);
     590    }
     591
     592    // ############################################################
     593    // #####                    Input States                  #####
    560594    // ##########                                        ##########
    561595    // ############################################################
  • code/trunk/src/core/input/InputManager.h

    r3370 r5695  
    8484            the constructor fails with an std::exception.
    8585        */
    86         InputManager(size_t windowHnd);
     86        InputManager();
    8787        //! Destroys all devices AND all input states!
    8888        ~InputManager();
     
    167167            { return devices_.size() - InputDeviceEnumerator::FirstJoyStick; }
    168168        //! Returns a pointer to the OIS InputManager. Only you if you know what you're doing!
    169         OIS::InputManager* getOISInputManager()
    170             { return this->oisInputManager_; }
     169        OIS::InputManager* getOISInputManager() { return this->oisInputManager_; }
     170        std::pair<int, int> getMousePosition() const;
    171171
    172172    private: // functions
     
    175175
    176176        // Intenal methods
    177         void loadDevices(size_t windowHnd);
     177        void loadDevices();
    178178        void loadMouse();
    179179        void loadJoySticks();
     
    193193        OIS::InputManager*                  oisInputManager_;      //!< OIS input manager
    194194        std::vector<InputDevice*>           devices_;              //!< List of all input devices (keyboard, mouse, joy sticks)
    195         // TODO: Get this from the GraphicsManager during reload
    196         size_t                              windowHnd_;            //!< Render window handle (used to reload the InputManager)
     195        bool                                bExclusiveMouse_;      //!< Currently applied mouse mode
    197196
    198197        // some internally handled states and handlers
  • code/trunk/src/core/input/InputState.cc

    r3327 r5695  
    3737        , bAlwaysGetsInput_(bAlwaysGetsInput)
    3838        , bTransparent_(bTransparent)
     39        , bExclusiveMouse_(true)
    3940        , bExpired_(true)
    4041        , handlers_(2)
  • code/trunk/src/core/input/InputState.h

    r3327 r5695  
    7575          not influence ony other InputState at all.
    7676
    77         Priorities
    78         **********
     77    @par Priorities
    7978        Every InputState has a priority when on the stack, but mostly this
    8079        priority is dynamic (InputStatePriority::Dynamic) which means that a state
     
    8382        a high priority (InputStatePriority::HighPriority). These 'special' ones
    8483        are used for features like the KeyDetector or the console. Use with care!
     84
     85    @par Exclusive/Non-Exclusive mouse Mode
     86        You can select a specific mouse mode that tells whether the application
     87        should have exclusive accessto it or not.
     88        When in non-exclusive mode, you can move the mouse out of the window
     89        like with any other normal window (only for windowed mode!).
     90        The setting is dictated by the topmost InputState that gets mouse events.
    8591    */
    8692    class _CoreExport InputState : public JoyStickQuantityListener
     
    114120        void setHandler        (InputHandler* handler);
    115121
     122        void setIsExclusiveMouse(bool value) { bExclusiveMouse_ = value; this->bExpired_ = true; }
     123        bool getIsExclusiveMouse() const { return bExclusiveMouse_; }
     124
    116125        //! Returns the name of the state (which is unique!)
    117126        const std::string& getName() const { return name_; }
     
    165174        const bool                  bAlwaysGetsInput_;      //!< See class declaration for explanation
    166175        const bool                  bTransparent_;          //!< See class declaration for explanation
     176        bool                        bExclusiveMouse_;       //!< See class declaration for explanation
    167177        int                         priority_;              //!< Current priority (might change)
    168178        bool                        bExpired_;              //!< See hasExpired()
  • code/trunk/src/core/input/KeyBinder.cc

    r3327 r5695  
    5555        mousePosition_[0] = 0;
    5656        mousePosition_[1] = 0;
    57 
    58         joyStickButtons_.reserve(1000);
    59         joyStickAxes_.reserve(1000);
    6057
    6158        RegisterRootObject(KeyBinder);
     
    167164            {
    168165                for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; ++i)
    169                     joyStickButtons_[iDev][i].readConfigValue(this->configFile_);
     166                    (*joyStickButtons_[iDev])[i].readConfigValue(this->configFile_);
    170167                for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; ++i)
    171                     joyStickAxes_[iDev][i].readConfigValue(this->configFile_);
     168                    (*joyStickAxes_[iDev])[i].readConfigValue(this->configFile_);
    172169            }
    173170        }
     
    179176    void KeyBinder::initialiseJoyStickBindings()
    180177    {
     178        while (joyStickAxes_.size() < joySticks_.size())
     179            joyStickAxes_.push_back(shared_ptr<JoyStickAxisVector>(new JoyStickAxisVector()));
     180        while (joyStickButtons_.size() < joySticks_.size())
     181            joyStickButtons_.push_back(shared_ptr<JoyStickButtonVector>(new JoyStickButtonVector()));
     182        // For the case the new size is smaller
    181183        this->joyStickAxes_.resize(joySticks_.size());
    182184        this->joyStickButtons_.resize(joySticks_.size());
     
    189191            for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++)
    190192            {
    191                 joyStickButtons_[iDev][i].name_ = JoyStickButtonCode::ByString[i];
    192                 joyStickButtons_[iDev][i].paramCommandBuffer_ = &paramCommandBuffer_;
    193                 joyStickButtons_[iDev][i].groupName_ = "JoyStickButtons_" + deviceName;
     193                (*joyStickButtons_[iDev])[i].name_ = JoyStickButtonCode::ByString[i];
     194                (*joyStickButtons_[iDev])[i].paramCommandBuffer_ = &paramCommandBuffer_;
     195                (*joyStickButtons_[iDev])[i].groupName_ = "JoyStickButtons_" + deviceName;
    194196            }
    195197            // joy stick axes
    196198            for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
    197199            {
    198                 joyStickAxes_[iDev][i].name_ = JoyStickAxisCode::ByString[i / 2];
     200                (*joyStickAxes_[iDev])[i].name_ = JoyStickAxisCode::ByString[i / 2];
    199201                if (i & 1)
    200                     joyStickAxes_[iDev][i].name_ += "Pos";
     202                    (*joyStickAxes_[iDev])[i].name_ += "Pos";
    201203                else
    202                     joyStickAxes_[iDev][i].name_ += "Neg";
    203                 joyStickAxes_[iDev][i].paramCommandBuffer_ = &paramCommandBuffer_;
    204                 joyStickAxes_[iDev][i].groupName_ = "JoyStickAxes_" + deviceName;
     204                    (*joyStickAxes_[iDev])[i].name_ += "Neg";
     205                (*joyStickAxes_[iDev])[i].paramCommandBuffer_ = &paramCommandBuffer_;
     206                (*joyStickAxes_[iDev])[i].groupName_ = "JoyStickAxes_" + deviceName;
    205207            }
    206208        }
     
    226228        {
    227229            for (unsigned int i = 0; i < JoyStickButtonCode::numberOfButtons; i++)
    228                 allButtons_[joyStickButtons_[iDev][i].groupName_ + "." + joyStickButtons_[iDev][i].name_] = &(joyStickButtons_[iDev][i]);
     230                allButtons_[(*joyStickButtons_[iDev])[i].groupName_ + "." + (*joyStickButtons_[iDev])[i].name_] = &((*joyStickButtons_[iDev])[i]);
    229231            for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
    230232            {
    231                 allButtons_[joyStickAxes_[iDev][i].groupName_ + "." + joyStickAxes_[iDev][i].name_] = &(joyStickAxes_[iDev][i]);
    232                 allHalfAxes_.push_back(&(joyStickAxes_[iDev][i]));
     233                allButtons_[(*joyStickAxes_[iDev])[i].groupName_ + "." + (*joyStickAxes_[iDev])[i].name_] = &((*joyStickAxes_[iDev])[i]);
     234                allHalfAxes_.push_back(&((*joyStickAxes_[iDev])[i]));
    233235            }
    234236        }
     
    303305            for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
    304306            {
    305                 joyStickAxes_[iDev][i].absVal_ = 0.0f;
    306                 joyStickAxes_[iDev][i].relVal_ = 0.0f;
     307                (*joyStickAxes_[iDev])[i].absVal_ = 0.0f;
     308                (*joyStickAxes_[iDev])[i].relVal_ = 0.0f;
    307309            }
    308310        }
     
    366368        for (unsigned int i = 0; i < JoyStickAxisCode::numberOfAxes * 2; i++)
    367369        {
    368             tickHalfAxis(joyStickAxes_[joyStick][i]);
     370            tickHalfAxis((*joyStickAxes_[joyStick])[i]);
    369371        }
    370372    }
     
    481483    {
    482484        int i = axisID * 2;
    483         JoyStickAxisVector& axis = joyStickAxes_[device];
     485        JoyStickAxisVector& axis = *joyStickAxes_[device];
    484486        if (value < 0)
    485487        {
  • code/trunk/src/core/input/KeyBinder.h

    r3327 r5695  
    4141#include <string>
    4242#include <vector>
     43#include <boost/shared_ptr.hpp>
    4344
    4445#include "InputHandler.h"
     
    115116        };
    116117        //! Actual key bindings for joy stick buttons
    117         std::vector<JoyStickButtonVector> joyStickButtons_;
     118        std::vector<shared_ptr<JoyStickButtonVector> > joyStickButtons_;
    118119        //! Helper class to use something like std:vector<HalfAxis[48]>
    119120        struct JoyStickAxisVector
     
    123124        };
    124125        //! Actual key bindings for joy stick axes (and sliders)
    125         std::vector<JoyStickAxisVector> joyStickAxes_;
     126        std::vector<shared_ptr<JoyStickAxisVector> > joyStickAxes_;
    126127
    127128        //! Pointer map with all Buttons, including half axes
     
    191192
    192193    inline void KeyBinder::buttonPressed (unsigned int device, JoyStickButtonCode::ByEnum button)
    193     { joyStickButtons_[device][button].execute(KeybindMode::OnPress); }
     194    { (*joyStickButtons_[device])[button].execute(KeybindMode::OnPress); }
    194195
    195196    inline void KeyBinder::buttonReleased(unsigned int device, JoyStickButtonCode::ByEnum button)
    196     { joyStickButtons_[device][button].execute(KeybindMode::OnRelease); }
     197    { (*joyStickButtons_[device])[button].execute(KeybindMode::OnRelease); }
    197198
    198199    inline void KeyBinder::buttonHeld    (unsigned int device, JoyStickButtonCode::ByEnum button)
    199     { joyStickButtons_[device][button].execute(KeybindMode::OnHold); }
     200    { (*joyStickButtons_[device])[button].execute(KeybindMode::OnHold); }
    200201
    201202    inline void KeyBinder::allDevicesUpdated(float dt)
  • code/trunk/src/core/input/KeyDetector.cc

    r3327 r5695  
    7070    {
    7171        KeyBinder::JoyStickQuantityChanged(joyStickList);
    72         setCallbackCommand(callbackCommand_);
     72        if (!callbackCommand_.empty())
     73            setCallbackCommand(callbackCommand_);
    7374    }
    7475}
Note: See TracChangeset for help on using the changeset viewer.