Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/tutorial/src/core/input/SimpleInputState.h @ 3050

Last change on this file since 3050 was 1887, checked in by rgrieder, 16 years ago

FIRST THINGS FIRST: Delete or rename your keybindings.ini (def_keybindings.ini already has the most important bindings) or else you won't be able to do anything!

Changes:

  • Multiple joy stick support should now fully work with KeyBinder too (only tested with 0/1 joystick)
  • Reloading the OIS Devices now works with KeyBinder too
  • Modified ConfigValueContainer to accept arbitrary section names
  • added tkeybind to temporary bind a command to a key
  • Fixed dlleport issue in ArgumentCompletionFunctions.h

Internal changes:

  • General cleanup in initialisation of KeyBinder
  • All names of keys/buttons/axes are now statically saved in InputInterfaces.h
  • Move a magic value in KeyBinder to a configValue (MouseWheelStepSize_)
  • Separated ConfigValues from Keybinding ConfigValueContainer in KeyBinder (looks much nicer now ;))
  • Moved some performance critical small function to the inline section
  • Removed the ugly keybind function construct from the InputManager
  • More 'harmonising' work in KeyBinder
  • Property svn:eol-style set to native
File size: 6.1 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*/
33
34#ifndef _SimpleInputState_H__
35#define _SimpleInputState_H__
36
37#include "core/CorePrereqs.h"
38
39#include <vector>
40#include <cassert>
41#include "InputInterfaces.h"
42#include "InputState.h"
43
44namespace orxonox
45{
46    class _CoreExport SimpleInputState : public InputState
47    {
48        friend class InputManager;
49
50    public:
51        void setKeyHandler        (KeyHandler* handler) { keyHandler_ = handler; update(); }
52        void setMouseHandler      (MouseHandler* handler) { mouseHandler_ = handler; update(); }
53        bool setJoyStickHandler   (JoyStickHandler* handler, unsigned int joyStickID);
54        bool setJoyStickHandler   (JoyStickHandler* handler);
55        bool setHandler(InputHandler* handler);
56
57    private:
58        SimpleInputState();
59        ~SimpleInputState() { }
60
61        void tickInput(float dt);
62        void tickInput(float dt, unsigned int device);
63
64        void keyPressed (const KeyEvent& evt);
65        void keyReleased(const KeyEvent& evt);
66        void keyHeld    (const KeyEvent& evt);
67
68        void mouseButtonPressed (MouseButtonCode::ByEnum id);
69        void mouseButtonReleased(MouseButtonCode::ByEnum id);
70        void mouseButtonHeld    (MouseButtonCode::ByEnum id);
71        void mouseMoved         (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
72        void mouseScrolled      (int abs, int rel);
73
74        void joyStickButtonPressed (unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
75        void joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
76        void joyStickButtonHeld    (unsigned int joyStickID, JoyStickButtonCode::ByEnum id);
77        void joyStickAxisMoved     (unsigned int joyStickID, unsigned int axis, float value);
78
79        void update();
80        void numberOfJoySticksChanged(unsigned int n);
81
82        KeyHandler*                   keyHandler_;
83        MouseHandler*                 mouseHandler_;
84        std::vector<JoyStickHandler*> joyStickHandler_;
85        JoyStickHandler*              joyStickHandlerAll_;
86        std::vector<InputHandler*>    allHandlers_;
87    };
88
89    inline void SimpleInputState::tickInput(float dt)
90    {
91        for (unsigned int i = 0; i < allHandlers_.size(); ++i)
92        {
93            allHandlers_[i]->tickInput(dt);
94        }
95    }
96
97    inline void SimpleInputState::tickInput(float dt, unsigned int device)
98    {
99        switch (device)
100        {
101        case InputDevice::Keyboard:
102            if (keyHandler_)
103                keyHandler_->tickKey(dt);
104            break;
105
106        case InputDevice::Mouse:
107            if (mouseHandler_)
108                mouseHandler_->tickMouse(dt);
109            break;
110
111        default: // joy sticks
112            if (joyStickHandler_[device - 2])
113                joyStickHandler_[device - 2]->tickJoyStick(dt, device - 2);
114            break;
115        }
116    }
117
118    inline void SimpleInputState::keyReleased(const KeyEvent& evt)
119    {
120        if (keyHandler_)
121            keyHandler_->keyReleased(evt);
122    }
123
124    inline void SimpleInputState::keyHeld(const KeyEvent& evt)
125    {
126        if (keyHandler_)
127            keyHandler_->keyHeld(evt);
128    }
129
130    inline void SimpleInputState::mouseMoved(IntVector2 abs, IntVector2 rel, IntVector2 clippingSize)
131    {
132        if (mouseHandler_)
133            mouseHandler_->mouseMoved(abs, rel, clippingSize);
134    }
135
136    inline void SimpleInputState::mouseScrolled(int abs, int rel)
137    {
138        if (mouseHandler_)
139            mouseHandler_->mouseScrolled(abs, rel);
140    }
141
142    inline void SimpleInputState::mouseButtonPressed(MouseButtonCode::ByEnum id)
143    {
144        if (mouseHandler_)
145            mouseHandler_->mouseButtonPressed(id);
146    }
147
148    inline void SimpleInputState::mouseButtonReleased(MouseButtonCode::ByEnum id)
149    {
150        if (mouseHandler_)
151            mouseHandler_->mouseButtonReleased(id);
152    }
153
154    inline void SimpleInputState::mouseButtonHeld(MouseButtonCode::ByEnum id)
155    {
156        if (mouseHandler_)
157            mouseHandler_->mouseButtonHeld(id);
158    }
159
160    inline void SimpleInputState::joyStickAxisMoved(unsigned int joyStickID, unsigned int axis, float value)
161    {
162        assert(joyStickID < joyStickHandler_.size());
163        if (joyStickHandler_[joyStickID])
164            joyStickHandler_[joyStickID]->joyStickAxisMoved(joyStickID, axis, value);
165    }
166
167    inline void SimpleInputState::joyStickButtonPressed(unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
168    {
169        assert(joyStickID < joyStickHandler_.size());
170        if (joyStickHandler_[joyStickID])
171            joyStickHandler_[joyStickID]->joyStickButtonPressed(joyStickID, id);
172    }
173
174    inline void SimpleInputState::joyStickButtonReleased(unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
175    {
176        assert(joyStickID < joyStickHandler_.size());
177        if (joyStickHandler_[joyStickID])
178            joyStickHandler_[joyStickID]->joyStickButtonReleased(joyStickID, id);
179    }
180
181    inline void SimpleInputState::joyStickButtonHeld(unsigned int joyStickID, JoyStickButtonCode::ByEnum id)
182    {
183        assert(joyStickID < joyStickHandler_.size());
184        if (joyStickHandler_[joyStickID])
185            joyStickHandler_[joyStickID]->joyStickButtonHeld(joyStickID, id);
186    }
187}
188
189#endif /* _SimpleInputState_H__ */
Note: See TracBrowser for help on using the repository browser.