Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core4/src/core/input/InputManager.h @ 3276

Last change on this file since 3276 was 3276, checked in by rgrieder, 15 years ago

Moved grab/ungrab mouse hack for Linux from InputManager to Mouse.

  • Property svn:eol-style set to native
File size: 5.5 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29/**
30@file
31@brief
32    Implementation of a little Input handler that distributes everything
33    coming from OIS.
34*/
35
36#ifndef _InputManager_H__
37#define _InputManager_H__
38
39#include "InputPrereqs.h"
40
41#include <map>
42#include <set>
43#include <string>
44#include <vector>
45
46#include "util/Math.h"
47#include "util/OrxEnum.h"
48#include "core/OrxonoxClass.h"
49
50namespace orxonox
51{
52    struct InputStatePriority : OrxEnum<InputStatePriority>
53    {
54        OrxEnumConstructors(InputStatePriority);
55
56        static const int Empty        = -1;
57        static const int Dynamic      = 0;
58
59        static const int HighPriority = 1000;
60        static const int Console      = HighPriority + 0;
61        static const int Calibrator   = HighPriority + 1;
62        static const int Detector     = HighPriority + 2;
63    };
64
65    /**
66    @brief
67        Captures and distributes mouse and keyboard input.
68    */
69    class _CoreExport InputManager : public OrxonoxClass
70    {
71        // --> setConfigValues is private
72        friend class ClassIdentifier<InputManager>;
73
74    public:
75        enum InputManagerState
76        {
77            Uninitialised    = 0x00,
78            OISReady         = 0x01,
79            InternalsReady   = 0x02,
80            Ticking          = 0x04,
81            Calibrating      = 0x08,
82            ReloadRequest    = 0x10,
83        };
84
85        InputManager (size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight);
86        ~InputManager();
87
88        void initialise(size_t windowHnd, unsigned int windowWidth, unsigned int windowHeight);
89
90        void reloadInputSystem();
91
92        void clearBuffers();
93
94        void setWindowExtents(const int width, const int height);
95        void setKeyDetectorCallback(const std::string& command);
96
97        InputState* createInputState(const std::string& name, bool bAlwaysGetsInput = false, bool bTransparent = false, InputStatePriority priority = InputStatePriority::Dynamic);
98
99        InputState* getState       (const std::string& name);
100        InputState* getCurrentState();
101        bool requestDestroyState   (const std::string& name);
102        bool requestEnterState     (const std::string& name);
103        bool requestLeaveState     (const std::string& name);
104
105        OIS::InputManager* getInputSystem() { return this->inputSystem_; }
106        bool checkJoyStickID(const std::string& idString) const;
107        unsigned int getJoyStickQuantity() const
108            { return devices_.size() - InputDeviceEnumerator::FirstJoyStick; }
109
110        void update(const Clock& time);
111
112        static InputManager& getInstance()    { assert(singletonRef_s); return *singletonRef_s; }
113        static InputManager* getInstancePtr() { return singletonRef_s; }
114
115        // console commands
116        static void calibrate();
117        static void reload();
118
119    private: // functions
120        // don't mess with a Singleton
121        InputManager(const InputManager&);
122
123        // Intenal methods
124        void _initialiseKeyboard();
125        void _initialiseMouse(unsigned int windowWidth, unsigned int windowHeight);
126        void _initialiseJoySticks();
127
128        void _startCalibration();
129        void _stopCalibration();
130
131        void _destroyState(InputState* state);
132
133        void _reload();
134
135        void _updateActiveStates();
136        bool _configureInputState(InputState* state, const std::string& name, bool bAlwaysGetsInput, bool bTransparent, int priority);
137
138        void setConfigValues();
139
140    private: // variables
141        OIS::InputManager*                  inputSystem_;          //!< OIS input manager
142        std::vector<InputDevice*>           devices_;              //!< List of all input devices (keyboard, mouse, joy sticks)
143        size_t                              windowHnd_;            //!< Render window handle
144        InputManagerState                   internalState_;        //!< Current internal state
145
146        // some internally handled states and handlers
147        InputState*                         stateEmpty_;
148        KeyDetector*                        keyDetector_;          //!< KeyDetector instance
149        InputBuffer*                        calibratorCallbackBuffer_;
150
151        std::map<std::string, InputState*>  inputStatesByName_;
152
153        std::set<InputState*>               stateEnterRequests_;   //!< Request to enter a new state
154        std::set<InputState*>               stateLeaveRequests_;   //!< Request to leave a running state
155        std::set<InputState*>               stateDestroyRequests_; //!< Request to destroy a state
156
157        std::map<int, InputState*>          activeStates_;
158        std::vector<InputState*>            activeStatesTicked_;
159
160        static InputManager*                singletonRef_s;
161    };
162}
163
164#endif /* _InputManager_H__ */
Note: See TracBrowser for help on using the repository browser.