Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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    {
Note: See TracChangeset for help on using the changeset viewer.