Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1641 for code


Ignore:
Timestamp:
Jul 22, 2008, 9:16:35 PM (16 years ago)
Author:
rgrieder
Message:

some de-bugging
added enum for joy stick buttons
some more little fixes

Location:
code/branches/gui/src
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gui/src/core/Shell.cc

    r1638 r1641  
    3333#include "Core.h"
    3434#include "ConsoleCommand.h"
    35 #include "input/InputInterfaces.h"
    36 #include "input/SimpleInputState.h"
    37 #include "input/InputManager.h"
    3835
    3936#define SHELL_UPDATE_LISTENERS(function) \
     
    6158        this->inputBuffer_ = new InputBuffer();
    6259        this->configureInputBuffer();
    63         InputManager::createSimpleInputState("console", 40)->setKeyHandler(this->inputBuffer_);
    6460
    6561        this->outputBuffer_.registerListener(this);
     
    7066    Shell::~Shell()
    7167    {
    72         SimpleInputState * inputState = dynamic_cast<SimpleInputState*>(InputManager::getState("console"));
    73         if (inputState)
    74         {
    75             inputState->removeAndDestroyAllHandlers();
    76             InputManager::destroyState("console");
    77         }
     68        if (this->inputBuffer_)
     69            delete this->inputBuffer_;
    7870    }
    7971
  • code/branches/gui/src/core/Shell.h

    r1638 r1641  
    7171            void unregisterListener(ShellListener* listener);
    7272
    73             inline InputBuffer& getInputBuffer()
    74                 { return (*this->inputBuffer_); }
     73            inline InputBuffer* getInputBuffer()
     74                { return this->inputBuffer_; }
    7575            inline OutputBuffer& getOutputBuffer()
    7676                { return this->outputBuffer_; }
  • code/branches/gui/src/core/input/ExtendedInputState.cc

    r1638 r1641  
    118118    }
    119119
    120     void ExtendedInputState::joyStickButtonPressed(unsigned int joyStickID, unsigned int button)
     120    void ExtendedInputState::joyStickButtonPressed(unsigned int joyStickID, JoyStickButton::Enum id)
    121121    {
    122122        assert(joyStickID < joyStickHandlers_.size());
    123123        for (unsigned int i = 0; i < joyStickHandlers_[joyStickID].size(); i++)
    124             joyStickHandlers_[joyStickID][i]->joyStickButtonPressed(joyStickID, button);
    125     }
    126 
    127     void ExtendedInputState::joyStickButtonReleased(unsigned int joyStickID, unsigned int button)
     124            joyStickHandlers_[joyStickID][i]->joyStickButtonPressed(joyStickID, id);
     125    }
     126
     127    void ExtendedInputState::joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id)
    128128    {
    129129        assert(joyStickID < joyStickHandlers_.size());
    130130        for (unsigned int i = 0; i < joyStickHandlers_[joyStickID].size(); i++)
    131             joyStickHandlers_[joyStickID][i]->joyStickButtonReleased(joyStickID, button);
    132     }
    133 
    134     void ExtendedInputState::joyStickButtonHeld(unsigned int joyStickID, unsigned int button)
     131            joyStickHandlers_[joyStickID][i]->joyStickButtonReleased(joyStickID, id);
     132    }
     133
     134    void ExtendedInputState::joyStickButtonHeld(unsigned int joyStickID, JoyStickButton::Enum id)
    135135    {
    136136        assert(joyStickID < joyStickHandlers_.size());
    137137        for (unsigned int i = 0; i < joyStickHandlers_[joyStickID].size(); i++)
    138             joyStickHandlers_[joyStickID][i]->joyStickButtonHeld(joyStickID, button);
     138            joyStickHandlers_[joyStickID][i]->joyStickButtonHeld(joyStickID, id);
    139139    }
    140140
  • code/branches/gui/src/core/input/ExtendedInputState.h

    r1638 r1641  
    8181        void mouseScrolled      (int abs, int rel);
    8282
    83         void joyStickButtonPressed (unsigned int joyStickID, unsigned int button);
    84         void joyStickButtonReleased(unsigned int joyStickID, unsigned int button);
    85         void joyStickButtonHeld    (unsigned int joyStickID, unsigned int button);
     83        void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id);
     84        void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id);
     85        void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id);
    8686        void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value);        void updateTickables();
    8787
  • code/branches/gui/src/core/input/InputBuffer.h

    r1638 r1641  
    171171
    172172            void tickInput(float dt);
    173             void tickInput(float dt, int device) { }
     173            void tickKey(float dt) { }
    174174
    175175            std::string buffer_;
  • code/branches/gui/src/core/input/InputInterfaces.h

    r1638 r1641  
    213213    }
    214214
     215    namespace JoyStickButton
     216    {
     217        enum Enum
     218        {
     219            Button0       =  0, Button1       =  1, Button2       =  2, Button3       =  3,
     220            Button4       =  4, Button5       =  5, Button6       =  6, Button7       =  7,
     221            Button8       =  8, Button9       =  9, Button10      = 10, Button11      = 11,
     222            Button12      = 12, Button13      = 13, Button14      = 14, Button15      = 15,
     223            Button16      = 16, Button17      = 17, Button18      = 18, Button19      = 19,
     224            Button20      = 20, Button21      = 21, Button22      = 22, Button23      = 23,
     225            Button24      = 24, Button25      = 25, Button26      = 26, Button27      = 27,
     226            Button28      = 28, Button29      = 29, Button30      = 30, Button31      = 31,
     227
     228            POV0North     = 32, POV0South     = 33, POV0East      = 34, POV0West      = 35,
     229            POV0NorthEast = 36, POV0SouthEast = 37, POV0NorthWest = 38, POV0SouthWest = 39,
     230
     231            POV1North     = 40, POV1South     = 41, POV1East      = 42, POV1West      = 43,
     232            POV1NorthEast = 44, POV1SouthEast = 45, POV1NorthWest = 46, POV1SouthWest = 47,
     233
     234            POV2North     = 48, POV2South     = 49, POV2East      = 50, POV2West      = 51,
     235            POV2NorthEast = 52, POV2SouthEast = 53, POV2NorthWest = 54, POV2SouthWest = 55,
     236
     237            POV3North     = 56, POV3South     = 57, POV3East      = 58, POV3West      = 59,
     238            POV3NorthEast = 60, POV3SouthEast = 61, POV3NorthWest = 62, POV3SouthWest = 63,
     239        };
     240    }
     241
    215242    namespace KeyboardModifier
    216243    {
     
    259286    };
    260287
    261     //typedef OIS::MouseState MouseState;
    262 
    263     /*class _CoreExport JoyStickState
    264     {
    265     public:
    266         JoyStickState(const OIS::JoyStickState& state, int ID) : OIS::JoyStickState(state), mJoyStickID(ID) { }
    267         JoyStickState() { clear(); }
    268         int mJoyStickID;
    269         JoyStickState() { clear(); }
    270 
    271         std::vector<bool> mButtons;
    272         int axes[16];
    273         std::vector<Vector3> mVectors;
    274     };*/
    275 
    276     /**
    277     @brief
    278         Helper struct to determine which handlers of an object (can implement
    279         multiple handlers) are active.
    280     */
    281     //struct HandlerState
    282     //{
    283     //    HandlerState() : keyboard(false), mouse(false) { }
    284     //    bool keyboard;
    285     //    bool mouse;
    286     //    std::vector<bool> joySticks;
    287     //};
    288288
    289289    class _CoreExport InputTickable
     
    292292        virtual ~InputTickable() { }
    293293        virtual void tickInput(float dt) = 0;
    294         //virtual void tickInput(float dt, unsigned int device) = 0;
    295294    };
    296295
     
    306305        virtual void keyReleased(const KeyEvent& evt) = 0;
    307306        virtual void keyHeld    (const KeyEvent& evt) = 0;
    308         virtual void tickKey    (float dt) { }
     307        virtual void tickKey    (float dt) = 0;
    309308    };
    310309
     
    322321        virtual void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize) = 0;
    323322        virtual void mouseScrolled      (int abs, int rel)     = 0;
    324         virtual void tickMouse          (float dt) { }
     323        virtual void tickMouse          (float dt) = 0;
    325324    };
    326325
     
    334333    public:
    335334        virtual ~JoyStickHandler() { }
    336         virtual void joyStickButtonPressed (unsigned int joyStickID, unsigned int button) = 0;
    337         virtual void joyStickButtonReleased(unsigned int joyStickID, unsigned int button) = 0;
    338         virtual void joyStickButtonHeld    (unsigned int joyStickID, unsigned int button) = 0;
     335        virtual void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id) = 0;
     336        virtual void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id) = 0;
     337        virtual void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id) = 0;
    339338        virtual void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value) = 0;
    340         //virtual bool joyStickVector3Moved  (unsigned int joyStickID, unsigned int index /*, fill list*/) {return true;}
    341         virtual void tickJoyStick          (float dt, unsigned int device) { }
     339        virtual void tickJoyStick          (float dt, unsigned int joyStick) = 0;
    342340    };
    343341
     
    346344    private:
    347345        void tickInput(float dt) { }
    348         void tickInput(float dt, unsigned int device) { }
     346        void tickJoyStick(float dt, unsigned int joyStick) { }
     347        void tickMouse(float dt) { }
     348        void tickKey(float dt) { }
    349349
    350350        void keyPressed (const KeyEvent& evt) { }
     
    358358        void mouseScrolled      (int abs, int rel) { }
    359359
    360         void joyStickButtonPressed (unsigned int joyStickID, unsigned int button) { }
    361         void joyStickButtonReleased(unsigned int joyStickID, unsigned int button) { }
    362         void joyStickButtonHeld    (unsigned int joyStickID, unsigned int button) { }
     360        void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id) { }
     361        void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id) { }
     362        void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id) { }
    363363        void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value) { }
    364364    };
  • code/branches/gui/src/core/input/InputManager.cc

    r1638 r1641  
    9191    /**
    9292    @brief
     93        Destructor itself only called at the end of the program, after main.
     94        Instance gets registered for destruction with atexit(.).
     95    */
     96    InputManager::~InputManager()
     97    {
     98        _destroy();
     99    }
     100
     101    /**
     102    @brief
    93103        The one instance of the InputManager is stored in this function.
     104        Only for internal use. Public Interface ist static.
    94105    @return
    95106        A reference to the only instance of the InputManager
     
    99110        static InputManager theOnlyInstance;
    100111        return theOnlyInstance;
    101     }
    102 
    103     /**
    104     @brief
    105         Destructor only called at the end of the program, after main.
    106     */
    107     InputManager::~InputManager()
    108     {
    109         _destroy();
    110112    }
    111113
     
    133135        {
    134136            CCOUT(3) << "Initialising Input System..." << std::endl;
    135             CCOUT(ORX_DEBUG) << "Initialising OIS components..." << std::endl;
     137            CCOUT(4) << "Initialising OIS components..." << std::endl;
    136138
    137139            OIS::ParamList paramList;
     
    180182            CCOUT(ORX_DEBUG) << "Initialising OIS components done." << std::endl;
    181183
    182             // InputManager holds the input buffer --> create one and add it.
    183             //buffer_ = new InputBuffer();
    184             //addKeyHandler(buffer_, "buffer");
    185             //Shell::getInstance().setInputBuffer(buffer_);
    186 
    187184            setConfigValues();
    188185
     
    204201            _updateActiveStates();
    205202
    206             CCOUT(ORX_DEBUG) << "Initialising complete." << std::endl;
     203            CCOUT(3) << "Initialising complete." << std::endl;
    207204        }
    208205        else
    209206        {
    210             CCOUT(ORX_WARNING) << "Warning: OIS compoments already initialised, skipping" << std::endl;
     207            CCOUT(2) << "Warning: OIS compoments already initialised, skipping" << std::endl;
    211208        }
    212209        return true;
     
    333330    }
    334331
     332    /**
     333    @brief
     334        Sets the size of all the different lists that are dependent on the number
     335        of joy stick devices created.
     336    @remarks
     337        No matter whether there are a mouse and/or keyboard, they will always
     338        occupy 2 places in the device number dependent lists.
     339    */
    335340    void InputManager::_redimensionLists()
    336341    {
     
    356361        activeStatesTop_.resize(devicesNum_);
    357362
    358         // inform all registered states
     363        // inform all states
    359364        for (std::map<int, InputState*>::const_iterator it = inputStatesByPriority_.begin();
    360365            it != inputStatesByPriority_.end(); ++it)
     
    364369    /**
    365370    @brief
    366         Sets the configurable values. Use keybindings.ini as file..
     371        Sets the configurable values.
     372        This mainly concerns joy stick calibrations.
    367373    */
    368374    void InputManager::setConfigValues()
    369375    {
    370         if (joySticksSize_)
     376        if (joySticksSize_ > 0)
    371377        {
    372378            std::vector<MultiTypeMath> coeffPos;
     
    386392            if (!cont)
    387393            {
    388                 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffPos", coeffPos);
     394                cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), "CoeffPos", coeffPos);
    389395                getIdentifier()->addConfigValueContainer("CoeffPos", cont);
    390396            }
     
    394400            if (!cont)
    395401            {
    396                 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "CoeffNeg", coeffNeg);
     402                cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), "CoeffNeg", coeffNeg);
    397403                getIdentifier()->addConfigValueContainer("CoeffNeg", cont);
    398404            }
     
    402408            if (!cont)
    403409            {
    404                 cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), "Zero", zero);
     410                cont = new ConfigValueContainer(CFT_Settings, getIdentifier(), "Zero", zero);
    405411                getIdentifier()->addConfigValueContainer("Zero", cont);
    406412            }
     
    425431    /**
    426432    @brief
    427         Destroys all the created input devices and sets the InputManager to construction state.
     433        Destroys all the created input devices. InputManager will be ready for a
     434        new initialisation.
    428435    */
    429436    void InputManager::_destroy()
     
    431438        if (inputSystem_)
    432439        {
    433             CCOUT(ORX_DEBUG) << "Destroying ..." << std::endl;
    434 
    435             // kick all active states 'nicely'
    436             for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin();
    437                 rit != activeStates_.rend(); ++rit)
    438                 (*rit).second->onLeave();
    439             activeStates_.clear();
    440 
    441             // destroy our own states
    442             stateEmpty_->removeAndDestroyAllHandlers();
    443             stateCalibrator_->removeAndDestroyAllHandlers();
    444             stateDetector_->removeAndDestroyAllHandlers();
    445             _destroyState(stateEmpty_);
    446             _destroyState(stateCalibrator_);
    447             _destroyState(stateDetector_);
    448             stateEmpty_ = 0;
    449             stateCalibrator_ = 0;
    450             stateDetector_ = 0;
    451 
    452             // we don't remove the other states yet because the singleton might still exist.
    453             // So people can still removeAndDestroy their states
    454             //inputStatesByName_.clear();
    455             //inputStatesByPriority_.clear();
    456 
    457             // destroy the devices
    458             _destroyKeyboard();
    459             _destroyMouse();
    460             _destroyJoySticks();
    461 
    462             _redimensionLists();
    463 
    464             OIS::InputManager::destroyInputSystem(inputSystem_);
    465             inputSystem_ = 0;
    466 
    467             CCOUT(ORX_DEBUG) << "Destroying done." << std::endl;
     440            try
     441            {
     442                CCOUT(3) << "Destroying ..." << std::endl;
     443
     444                // clear our own states
     445                stateEmpty_->removeAndDestroyAllHandlers();
     446                stateCalibrator_->removeAndDestroyAllHandlers();
     447                stateDetector_->removeAndDestroyAllHandlers();
     448
     449                // kick all active states 'nicely'
     450                for (std::map<int, InputState*>::reverse_iterator rit = activeStates_.rbegin();
     451                    rit != activeStates_.rend(); ++rit)
     452                {
     453                    (*rit).second->onLeave();
     454                }
     455                activeStates_.clear();
     456                _updateActiveStates();
     457
     458                // destroy all input states
     459                while (inputStatesByPriority_.size() > 0)
     460                {
     461                    _destroyState((*inputStatesByPriority_.rbegin()).second);
     462                }
     463
     464                stateEmpty_ = 0;
     465                stateCalibrator_ = 0;
     466                stateDetector_ = 0;
     467
     468                // destroy the devices
     469                _destroyKeyboard();
     470                _destroyMouse();
     471                _destroyJoySticks();
     472
     473                // 0 joy sticks now
     474                _redimensionLists();
     475
     476                OIS::InputManager::destroyInputSystem(inputSystem_);
     477                inputSystem_ = 0;
     478
     479                CCOUT(3) << "Destroying done." << std::endl;
     480            }
     481            catch (OIS::Exception& ex)
     482            {
     483                CCOUT(1) << "An exception has occured while destroying:\n" << ex.what() << std::endl;
     484            }
    468485        }
    469486    }
     
    479496        keyboard_ = 0;
    480497        keysDown_.clear();
    481         CCOUT(ORX_DEBUG) << "Keyboard destroyed." << std::endl;
     498        CCOUT(4) << "Keyboard destroyed." << std::endl;
    482499    }
    483500
     
    492509        mouse_ = 0;
    493510        mouseButtonsDown_.clear();
    494         CCOUT(ORX_DEBUG) << "Mouse destroyed." << std::endl;
     511        CCOUT(4) << "Mouse destroyed." << std::endl;
    495512    }
    496513
     
    510527            joySticks_.clear();
    511528        }
    512         CCOUT(ORX_DEBUG) << "Joy sticks destroyed." << std::endl;
     529        CCOUT(4) << "Joy sticks destroyed." << std::endl;
    513530    }
    514531
     
    597614    }
    598615
     616    /**
     617    @brief
     618        Updates the currently active states (according to activeStates_) for each device.
     619        Also, a list of all active states (no duplicates!) is compiled for the general tick.
     620    */
    599621    void InputManager::_updateActiveStates()
    600622    {
     
    616638    }
    617639
     640    /**
     641    @brief
     642        Processes the accumultated data for the joy stick calibration.
     643    */
    618644    void InputManager::_completeCalibration()
    619645    {
     
    676702        // restore old input state
    677703        requestLeaveState("calibrator");
     704        bCalibrating_ = false;
    678705    }
    679706
     
    822849    // ###### Joy Stick Events ######
    823850
     851    /**
     852    @brief
     853        Returns the joy stick ID (orxonox) according to a OIS::JoyStickEvent
     854    */
    824855    inline unsigned int InputManager::_getJoystick(const OIS::JoyStickEvent& arg)
    825856    {
     
    839870
    840871        // check whether the button already is in the list (can happen when focus was lost)
    841         std::vector<int>& buttonsDown = joyStickButtonsDown_[iJoyStick];
     872        std::vector<JoyStickButton::Enum>& buttonsDown = joyStickButtonsDown_[iJoyStick];
    842873        unsigned int iButton = 0;
    843874        while (iButton < buttonsDown.size() && buttonsDown[iButton] != button)
    844875            iButton++;
    845876        if (iButton == buttonsDown.size())
    846             buttonsDown.push_back(button);
    847 
    848         activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, button);
     877            buttonsDown.push_back((JoyStickButton::Enum)button);
     878
     879        activeStatesTop_[2 + iJoyStick]->joyStickButtonPressed(iJoyStick, (JoyStickButton::Enum)button);
    849880
    850881        return true;
     
    856887
    857888        // remove the button from the joyStickButtonsDown_ list
    858         std::vector<int>& buttonsDown = joyStickButtonsDown_[iJoyStick];
     889        std::vector<JoyStickButton::Enum>& buttonsDown = joyStickButtonsDown_[iJoyStick];
    859890        for (unsigned int iButton = 0; iButton < buttonsDown.size(); iButton++)
    860891        {
     
    866897        }
    867898
    868         activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, button);
     899        activeStatesTop_[2 + iJoyStick]->joyStickButtonReleased(iJoyStick, (JoyStickButton::Enum)button);
    869900
    870901        return true;
    871902    }
    872903
     904    /**
     905    @brief
     906        Calls the states for a particular axis with our enumeration.
     907        Used by OIS sliders and OIS axes.
     908    */
    873909    void InputManager::_fireAxis(unsigned int iJoyStick, int axis, int value)
    874910    {
     
    919955
    920956        // translate the POV into 8 simple buttons
     957
    921958        int lastState = povStates_[iJoyStick][id];
    922959        if (lastState & OIS::Pov::North)
     
    959996    }
    960997
    961     bool InputManager::initialiseKeyboard()
    962     {
    963         return _getInstance()._initialiseKeyboard();
    964     }
    965 
    966     bool InputManager::initialiseMouse()
    967     {
    968         return _getInstance()._initialiseMouse();
    969     }
    970 
    971     bool InputManager::initialiseJoySticks()
    972     {
    973         return _getInstance()._initialiseJoySticks();
    974     }
    975 
    976998    int InputManager::numberOfKeyboards()
    977999    {
     
    10301052    {
    10311053        _getInstance()._destroy();
    1032     }
    1033 
    1034     void InputManager::destroyKeyboard()
    1035     {
    1036         return _getInstance()._destroyKeyboard();
    1037     }
    1038 
    1039     void InputManager::destroyMouse()
    1040     {
    1041         return _getInstance()._destroyMouse();
    1042     }
    1043 
    1044     void InputManager::destroyJoySticks()
    1045     {
    1046         return _getInstance()._destroyJoySticks();
    10471054    }
    10481055
     
    10681075    }
    10691076
     1077    /**
     1078    @brief
     1079        Method for easily storing a string with the command executor. It is used by the
     1080        KeyDetector to get assign commands. The KeyDetector simply executes
     1081        the command 'storeKeyStroke myName' for each button/axis.
     1082    @remarks
     1083        This is only a temporary hack until we thourouhgly support multiple KeyBinders.
     1084    @param name
     1085        The name of the button/axis.
     1086    */
    10701087    void InputManager::storeKeyStroke(const std::string& name)
    10711088    {
     
    10751092    }
    10761093
     1094    /**
     1095    @brief
     1096        Assigns a command string to a key/button/axis. The name is determined via KeyDetector
     1097        and InputManager::storeKeyStroke(.).
     1098    @param command
     1099        Command string that can be executed by the CommandExecutor
     1100    */
    10771101    void InputManager::keyBind(const std::string& command)
    10781102    {
     
    10821106    }
    10831107
     1108    /**
     1109    @brief
     1110        Starts joy stick calibration.
     1111    */
    10841112    void InputManager::calibrate()
    10851113    {
     1114        _getInstance().bCalibrating_ = true;
    10861115        requestEnterState("calibrator");
    10871116    }
     
    11011130    @param name
    11021131        Unique name of the handler.
     1132    @param priority
     1133        Unique integer number. Higher means more prioritised.
    11031134    @return
    1104         True if added, false if name already existed.
     1135        True if added, false if name or priority already existed.
    11051136    */
    11061137    bool InputManager::_configureInputState(InputState* state, const std::string& name, int priority)
     
    11341165    }
    11351166
     1167    /**
     1168    @brief
     1169        Returns a new SimpleInputState and configures it first.
     1170    */
    11361171    SimpleInputState* InputManager::createSimpleInputState(const std::string &name, int priority)
    11371172    {
     
    11461181    }
    11471182
     1183    /**
     1184    @brief
     1185        Returns a new ExtendedInputState and configures it first.
     1186    */
    11481187    ExtendedInputState* InputManager::createExtendedInputState(const std::string &name, int priority)
    11491188    {
     
    11601199    /**
    11611200    @brief
    1162         Removes a Key handler from the list.
     1201        Removes an input state internally.
    11631202    @param name
    1164         Unique name of the handler.
     1203        Name of the handler.
    11651204    @return
    11661205        True if removal was successful, false if name was not found.
     1206    @remarks
     1207        You can't remove the internal states "empty", "calibrator" and "detector".
    11671208    */
    11681209    bool InputManager::destroyState(const std::string& name)
     
    11841225    /**
    11851226    @brief
    1186         Returns the pointer to a handler.
     1227        Returns the pointer to the requested InputState.
    11871228    @param name
    1188         Unique name of the handler.
     1229        Unique name of the state.
    11891230    @return
    11901231        Pointer to the instance, 0 if name was not found.
     
    12011242    /**
    12021243    @brief
    1203         Returns the current input handling method
     1244        Returns the current input state (there might be others active too!)
    12041245    @return
    1205         The current input mode.
     1246        The current highest prioritised active input state.
    12061247    */
    12071248    InputState* InputManager::getCurrentState()
     
    12121253    /**
    12131254    @brief
    1214         Enables a specific key handler that has already been added.
     1255        Activates a specific input state.
     1256        It might not be really activated if the priority is too low!
    12151257    @param name
    1216         Unique name of the handler.
     1258        Unique name of the state.
    12171259    @return
    12181260        False if name was not found, true otherwise.
     
    12301272    }
    12311273
     1274    /**
     1275    @brief
     1276        Deactivates a specific input state.
     1277    @param name
     1278        Unique name of the state.
     1279    @return
     1280        False if name was not found, true otherwise.
     1281    */
    12321282    bool InputManager::requestLeaveState(const std::string& name)
    12331283    {
  • code/branches/gui/src/core/input/InputManager.h

    r1638 r1641  
    9090        static bool initialise(const size_t windowHnd, int windowWidth, int windowHeight,
    9191                               bool createKeyboard = true, bool createMouse = true, bool createJoySticks = false);
    92         static bool initialiseKeyboard();
    93         static bool initialiseMouse();
    94         static bool initialiseJoySticks();
    9592        static int  numberOfKeyboards();
    9693        static int  numberOfMice();
     
    9895
    9996        static void destroy();
    100         static void destroyKeyboard();
    101         static void destroyMouse();
    102         static void destroyJoySticks();
    10397
    10498        //static bool isModifierDown(KeyboardModifier::Enum modifier);
     
    119113        static ExtendedInputState* createExtendedInputState(const std::string& name, int priority);
    120114        static bool destroyState (const std::string& name);
    121         //static bool removeState (const std::string& name);
    122115        static InputState* getState       (const std::string& name);
    123116        static InputState* getCurrentState();
     
    171164
    172165    private: // variables
    173         OIS::InputManager*                          inputSystem_;     //!< OIS input manager
    174         OIS::Keyboard*                              keyboard_;        //!< OIS mouse
    175         OIS::Mouse*                                 mouse_;           //!< OIS keyboard
    176         std::vector<OIS::JoyStick*>                 joySticks_;       //!< OIS joy sticks
    177         unsigned int                                joySticksSize_;
    178         unsigned int                                devicesNum_;
     166        OIS::InputManager*                  inputSystem_;          //!< OIS input manager
     167        OIS::Keyboard*                      keyboard_;             //!< OIS mouse
     168        OIS::Mouse*                         mouse_;                //!< OIS keyboard
     169        std::vector<OIS::JoyStick*>         joySticks_;            //!< OIS joy sticks
     170        unsigned int                        joySticksSize_;
     171        unsigned int                        devicesNum_;
    179172
    180173        // some internally handled states
    181         SimpleInputState*                                 stateDetector_;   //!< KeyDetector instance
    182         SimpleInputState*                                 stateCalibrator_;
    183         SimpleInputState*                                 stateEmpty_;
    184 
    185         std::map<std::string, InputState*>          inputStatesByName_;
    186         std::map<int, InputState*>                  inputStatesByPriority_;
    187 
    188         std::vector<InputState*> stateEnterRequests_;                  //!< Request to enter a new state
    189         std::vector<InputState*> stateLeaveRequests_;                    //!< Request to leave the current state
    190 
    191         std::map<int, InputState*> activeStates_;
    192         std::vector<InputState*>   activeStatesTop_;    //!< Current input states for joy stick events.
    193         std::vector<InputState*>   activeStatesTicked_;    //!< Current input states for joy stick events.
     174        SimpleInputState*                   stateDetector_;        //!< KeyDetector instance
     175        SimpleInputState*                   stateCalibrator_;
     176        SimpleInputState*                   stateEmpty_;
     177
     178        std::map<std::string, InputState*>  inputStatesByName_;
     179        std::map<int, InputState*>          inputStatesByPriority_;
     180
     181        std::vector<InputState*>            stateEnterRequests_;   //!< Request to enter a new state
     182        std::vector<InputState*>            stateLeaveRequests_;   //!< Request to leave the current state
     183
     184        std::map<int, InputState*>          activeStates_;
     185        std::vector<InputState*>            activeStatesTop_;      //!< Current input states for joy stick events.
     186        std::vector<InputState*>            activeStatesTicked_;   //!< Current input states for joy stick events.
    194187
    195188        // joystick calibration
    196189        //std::vector<int> marginalsMaxConfig_;
    197190        //std::vector<int> marginalsMinConfig_;
    198         int marginalsMax_[24];
    199         int marginalsMin_[24];
    200         bool bCalibrated_;
    201         bool bCalibrating_;
    202 
    203         unsigned int keyboardModifiers_;           //!< Bit mask representing keyboard modifiers
    204         //! Keeps track of the joy stick POV states
    205         std::vector<POVStates>                      povStates_;
    206         //! Keeps track of the possibly two slider axes
    207         std::vector<SliderStates>                   sliderStates_;
    208         std::vector<JoyStickCalibration>            joySticksCalibration_;
    209 
    210         std::vector<Key>                            keysDown_;
    211         std::vector<MouseButton::Enum>              mouseButtonsDown_;
    212         std::vector<std::vector<int> >              joyStickButtonsDown_;
    213 
    214         static std::string                          bindingCommmandString_s;
     191        int                                 marginalsMax_[24];
     192        int                                 marginalsMin_[24];
     193        bool                                bCalibrated_;
     194        bool                                bCalibrating_;
     195
     196        unsigned int                        keyboardModifiers_;    //!< Bit mask representing keyboard modifiers.
     197        std::vector<POVStates>              povStates_;            //!< Keeps track of the joy stick POV states.
     198        std::vector<SliderStates>           sliderStates_;         //!< Keeps track of the possibly two slider axes.
     199        std::vector<JoyStickCalibration>    joySticksCalibration_;
     200
     201        std::vector<Key>                    keysDown_;
     202        std::vector<MouseButton::Enum>      mouseButtonsDown_;
     203        std::vector<std::vector<JoyStickButton::Enum> >  joyStickButtonsDown_;
     204
     205        static std::string                  bindingCommmandString_s;
    215206    };
    216207
  • code/branches/gui/src/core/input/InputState.h

    r1638 r1641  
    8484        virtual void mouseScrolled      (int abs, int rel) = 0;
    8585
    86         virtual void joyStickButtonPressed (unsigned int joyStickID, unsigned int button) = 0;
    87         virtual void joyStickButtonReleased(unsigned int joyStickID, unsigned int button) = 0;
    88         virtual void joyStickButtonHeld    (unsigned int joyStickID, unsigned int button) = 0;
     86        virtual void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id) = 0;
     87        virtual void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id) = 0;
     88        virtual void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id) = 0;
    8989        virtual void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value) = 0;
    9090
  • code/branches/gui/src/core/input/KeyBinder.cc

    r1638 r1641  
    374374    }
    375375
    376     void KeyBinder::tickJoyStick(float dt, int device)
     376    void KeyBinder::tickJoyStick(float dt, unsigned int joyStick)
    377377    {
    378378        tickDevices(8, nHalfAxes_s);
     
    448448
    449449
    450     void KeyBinder::joyStickButtonPressed (unsigned int joyStickID, unsigned int button)
    451     { joyStickButtons_[button].execute(KeybindMode::OnPress); }
    452 
    453     void KeyBinder::joyStickButtonReleased(unsigned int joyStickID, unsigned int button)
    454     { joyStickButtons_[button].execute(KeybindMode::OnRelease); }
    455 
    456     void KeyBinder::joyStickButtonHeld    (unsigned int joyStickID, unsigned int button)
    457     { joyStickButtons_[button].execute(KeybindMode::OnHold); }
     450    void KeyBinder::joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id)
     451    { joyStickButtons_[id].execute(KeybindMode::OnPress); }
     452
     453    void KeyBinder::joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id)
     454    { joyStickButtons_[id].execute(KeybindMode::OnRelease); }
     455
     456    void KeyBinder::joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id)
     457    { joyStickButtons_[id].execute(KeybindMode::OnHold); }
    458458
    459459    /**
  • code/branches/gui/src/core/input/KeyBinder.h

    r1638 r1641  
    6868        void tickKey(float dt) { }
    6969        void tickMouse(float dt);
    70         void tickJoyStick(float dt, int device);
     70        void tickJoyStick(float dt, unsigned int joyStick);
    7171        void tickDevices(unsigned int begin, unsigned int end);
    7272
     
    8383        void mouseScrolled      (int abs, int rel);
    8484
    85         void joyStickButtonPressed (unsigned int joyStickID, unsigned int button);
    86         void joyStickButtonReleased(unsigned int joyStickID, unsigned int button);
    87         void joyStickButtonHeld    (unsigned int joyStickID, unsigned int button);
     85        void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id);
     86        void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id);
     87        void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id);
    8888        void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value);
    8989
  • code/branches/gui/src/core/input/SimpleInputState.cc

    r1638 r1641  
    123123    }
    124124
    125     void SimpleInputState::joyStickButtonPressed(unsigned int joyStickID, unsigned int button)
    126     {
    127         assert(joyStickID < joyStickHandler_.size());
    128         if (joyStickHandler_[joyStickID])
    129             joyStickHandler_[joyStickID]->joyStickButtonPressed(joyStickID, button);
    130     }
    131 
    132     void SimpleInputState::joyStickButtonReleased(unsigned int joyStickID, unsigned int button)
    133     {
    134         assert(joyStickID < joyStickHandler_.size());
    135         if (joyStickHandler_[joyStickID])
    136             joyStickHandler_[joyStickID]->joyStickButtonReleased(joyStickID, button);
    137     }
    138 
    139     void SimpleInputState::joyStickButtonHeld(unsigned int joyStickID, unsigned int button)
    140     {
    141         assert(joyStickID < joyStickHandler_.size());
    142         if (joyStickHandler_[joyStickID])
    143             joyStickHandler_[joyStickID]->joyStickButtonHeld(joyStickID, button);
     125    void SimpleInputState::joyStickButtonPressed(unsigned int joyStickID, JoyStickButton::Enum id)
     126    {
     127        assert(joyStickID < joyStickHandler_.size());
     128        if (joyStickHandler_[joyStickID])
     129            joyStickHandler_[joyStickID]->joyStickButtonPressed(joyStickID, id);
     130    }
     131
     132    void SimpleInputState::joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id)
     133    {
     134        assert(joyStickID < joyStickHandler_.size());
     135        if (joyStickHandler_[joyStickID])
     136            joyStickHandler_[joyStickID]->joyStickButtonReleased(joyStickID, id);
     137    }
     138
     139    void SimpleInputState::joyStickButtonHeld(unsigned int joyStickID, JoyStickButton::Enum id)
     140    {
     141        assert(joyStickID < joyStickHandler_.size());
     142        if (joyStickHandler_[joyStickID])
     143            joyStickHandler_[joyStickID]->joyStickButtonHeld(joyStickID, id);
    144144    }
    145145
  • code/branches/gui/src/core/input/SimpleInputState.h

    r1638 r1641  
    7272        void mouseScrolled      (int abs, int rel);
    7373
    74         void joyStickButtonPressed (unsigned int joyStickID, unsigned int button);
    75         void joyStickButtonReleased(unsigned int joyStickID, unsigned int button);
    76         void joyStickButtonHeld    (unsigned int joyStickID, unsigned int button);
     74        void joyStickButtonPressed (unsigned int joyStickID, JoyStickButton::Enum id);
     75        void joyStickButtonReleased(unsigned int joyStickID, JoyStickButton::Enum id);
     76        void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButton::Enum id);
    7777        void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value);
    7878
  • code/branches/gui/src/orxonox/GraphicsEngine.cc

    r1640 r1641  
    2222 *   Author:
    2323 *      Reto Grieder
     24 *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
    2425 *   Co-authors:
    25  *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007, Felix Schulthess
     26 *      Felix Schulthess
    2627 *
    2728 */
     
    8990        RegisterObject(GraphicsEngine);
    9091
     92        assert(singletonRef_s == 0);
    9193        singletonRef_s = this;
    9294
     
    305307        //Ogre::TextureManager::getSingleton().setDefaultNumMipmaps(5);
    306308
    307         // create a full screen viewport in which to render the scene and the loading screen
    308         // The GUI uses its own one to be able to render on top of everything.
    309         // That explains why the Z order here is only 1 and not 0 (top most)
    310         this->viewport_ = this->renderWindow_->addViewport(0, 1);
     309        // create a full screen viewport
     310        this->viewport_ = this->renderWindow_->addViewport(0, 0);
    311311
    312312        return true;
  • code/branches/gui/src/orxonox/GraphicsEngine.h

    r1640 r1641  
    2222 *   Author:
    2323 *      Reto Grieder
     24 *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
    2425 *   Co-authors:
    25  *      Benjamin Knecht <beni_at_orxonox.net>, (C) 2007, Felix Schulthess
     26 *      Felix Schulthess
    2627 *
    2728 */
     
    8889
    8990        static GraphicsEngine& getSingleton();
    90         static GraphicsEngine* getSingletonPtr() { return &getSingleton(); }
     91        static GraphicsEngine* getSingletonPtr() { return singletonRef_s; }
    9192
    9293    private:
  • code/branches/gui/src/orxonox/Orxonox.cc

    r1640 r1641  
    300300  }
    301301
    302   void Orxonox::loadGame(const std::string& name)
     302  /*static*/ void Orxonox::loadGame(const std::string& name)
    303303  {
    304304      const GameMode& mode = Settings::getGameMode(name);
  • code/branches/gui/src/orxonox/gui/GUIManager.h

    r1640 r1641  
    103103
    104104        void tickInput(float dt) { }
     105        void tickKey(float dt) { }
     106        void tickMouse(float dt) { }
    105107
    106108        void loadScenes();
  • code/branches/gui/src/orxonox/gui/OgreCEGUIRenderer.cpp

    r1638 r1641  
    191191    // GUI (uses its own viewport to be able render on top of all viewports).
    192192    // But since we don't use overlays in the GUI, it doesn't matter.
    193     //if (d_render_sys->_getViewport()->getOverlaysEnabled() && !d_quadlist.empty())
    194     if (!d_quadlist.empty())
     193    // ORXONOX REVERT: Changes are not in place anymore, but might be in the future!
     194    if (d_render_sys->_getViewport()->getOverlaysEnabled() && !d_quadlist.empty())
     195    //if (!d_quadlist.empty())
    195196    {
    196197        /// Quad list needs to be sorted and thus the vertex buffer rebuilt. If not, we can
     
    493494    // GUI (uses its own viewport to be able render on top of all viewports).
    494495    // But since we don't use overlays in the GUI, it doesn't matter.
    495     //if (d_render_sys->_getViewport()->getOverlaysEnabled())
    496     if (true)
     496    // ORXONOX REVERT: Changes are not in place anymore, but might be in the future!
     497    if (d_render_sys->_getViewport()->getOverlaysEnabled())
     498    //if (true)
    497499    {
    498500        z = -1 + z;
  • code/branches/gui/src/orxonox/overlays/console/InGameConsole.cc

    r1638 r1641  
    4646#include "core/ConsoleCommand.h"
    4747#include "core/input/InputManager.h"
     48#include "core/input/SimpleInputState.h"
     49#include "core/input/InputBuffer.h"
    4850#include "GraphicsEngine.h"
    4951
     
    6668        , consoleOverlayBorder_(0)
    6769        , consoleOverlayTextAreas_(0)
    68         , emptySceneManager_(0)
    69         , emptyCamera_(0)
    70         , viewport_(0)
    7170    {
    7271        RegisterObject(InGameConsole);
     
    118117    void InGameConsole::initialise()
    119118    {
     119        // create the corresponding input state
     120        InputManager::createSimpleInputState("console", 40)->setKeyHandler(Shell::getInstance().getInputBuffer());
     121
    120122        // create overlay and elements
    121123        Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
     
    195197        Shell::getInstance().addOutputLevel(true);
    196198
    197         // create a sceneManager in order to render in our own viewport
    198         this->emptySceneManager_ = Ogre::Root::getSingleton()
    199             .createSceneManager(Ogre::ST_GENERIC, "Console/EmptySceneManager");
    200         this->emptyCamera_ = this->emptySceneManager_->createCamera("Console/EmptyCamera");
    201         this->viewport_ = GraphicsEngine::getSingleton().getRenderWindow()->addViewport(emptyCamera_, 10);
    202         this->viewport_->setOverlaysEnabled(true);
    203         this->viewport_->setClearEveryFrame(false);
    204 
    205199        COUT(4) << "Info: InGameConsole initialized" << std::endl;
    206200    }
     
    211205    void InGameConsole::destroy()
    212206    {
     207        this->deactivate();
     208
     209        // destroy the input state previously created
     210        SimpleInputState * inputState = dynamic_cast<SimpleInputState*>(InputManager::getState("console"));
     211        if (inputState)
     212            InputManager::destroyState("console");
     213
    213214        Ogre::OverlayManager* ovMan = Ogre::OverlayManager::getSingletonPtr();
    214215        if (ovMan)
     
    467468                if (output.size() > this->maxCharsPerLine_)
    468469                {
    469                     if (Shell::getInstance().getInputBuffer().getCursorPosition() < this->inputWindowStart_)
    470                         this->inputWindowStart_ = Shell::getInstance().getInputBuffer().getCursorPosition();
    471                     else if (Shell::getInstance().getInputBuffer().getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1))
    472                         this->inputWindowStart_ = Shell::getInstance().getInputBuffer().getCursorPosition() - this->maxCharsPerLine_ + 1;
     470                    if (Shell::getInstance().getInputBuffer()->getCursorPosition() < this->inputWindowStart_)
     471                        this->inputWindowStart_ = Shell::getInstance().getInputBuffer()->getCursorPosition();
     472                    else if (Shell::getInstance().getInputBuffer()->getCursorPosition() >= (this->inputWindowStart_ + this->maxCharsPerLine_ - 1))
     473                        this->inputWindowStart_ = Shell::getInstance().getInputBuffer()->getCursorPosition() - this->maxCharsPerLine_ + 1;
    473474
    474475                    output = output.substr(this->inputWindowStart_, this->maxCharsPerLine_);
  • code/branches/gui/src/orxonox/overlays/console/InGameConsole.h

    r1638 r1641  
    100100        Ogre::TextAreaOverlayElement** consoleOverlayTextAreas_;
    101101
    102         Ogre::SceneManager* emptySceneManager_;     //!< dummy SceneManager to render overlays in empty windows
    103         Ogre::Camera*       emptyCamera_;           //!< dummy camera to render overlays in empty windows
    104         Ogre::Viewport*     viewport_;
    105 
    106102        // config values
    107103        float relativeWidth;
Note: See TracChangeset for help on using the changeset viewer.