Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/input/src/core/InputHandler.cc @ 1118

Last change on this file since 1118 was 1118, checked in by rgrieder, 16 years ago
  • classed FloatParser to ExprParser class
File size: 6.6 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 Implementation of the different input handlers.
32 */
33
34#include "InputHandler.h"
35#include "Debug.h"
36#include "util/Convert.h"
37#include "InputEventListener.h"
38#include "InputEvent.h"
39#include "InputManager.h"
40#include "core/CommandExecutor.h"
41
42namespace orxonox
43{
44  // ###############################
45  // ###    InputHandlerGame     ###
46  // ###############################
47
48  /**
49    @brief standard constructor
50  */
51  InputHandlerGame::InputHandlerGame()
52  {
53  }
54
55  /**
56    @brief Destructor
57  */
58  InputHandlerGame::~InputHandlerGame()
59  {
60  }
61
62  /**
63    @brief Loads the key bindings from the ini file.
64    Currently, this is just a simple test routine that fills the list with numbers.
65  */
66  bool InputHandlerGame::loadBindings()
67  {
68    for (int i = 0; i < numberOfKeys_s; i++)
69    {
70      // simply write the key number (i) in the string
71      this->bindingsKeyPress_[i] = "";
72      this->bindingsKeyRelease_[i] = "";
73    }
74    this->bindingsKeyPress_[OIS::KC_NUMPADENTER] = "setInputMode " + getConvertedValue<int, std::string>(IM_KEYBOARD);
75    this->bindingsKeyPress_[OIS::KC_ESCAPE] = "exit";
76    this->bindingsKeyHold_[OIS::KC_U] = "exec disco.txt";
77    return true;
78  }
79
80  /**
81    @brief Event handler for the keyPressed Event.
82    @param e Event information
83  */
84  bool InputHandlerGame::keyPressed(const OIS::KeyEvent &e)
85  {
86    this->keysDown_.push_back(e.key);
87    // find the appropriate key binding
88    std::string cmdStr = bindingsKeyPress_[int(e.key)];
89    if (cmdStr != "")
90    {
91      CommandExecutor::execute(cmdStr);
92      COUT(3) << "Executing command: " << cmdStr << std::endl;
93    }
94    return true;
95  }
96
97  /**
98    @brief Event handler for the keyReleased Event.
99    @param e Event information
100  */
101  bool InputHandlerGame::keyReleased(const OIS::KeyEvent &e)
102  {
103    // remove the key from the keysDown_ list
104    for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)
105    {
106      if (*it == e.key)
107      {
108        keysDown_.erase(it);
109        break;
110      }
111    }
112
113    // find the appropriate key binding
114    std::string cmdStr = bindingsKeyRelease_[int(e.key)];
115    if (cmdStr != "")
116    {
117      CommandExecutor::execute(cmdStr);
118      COUT(3) << "Executing command: " << cmdStr << std::endl;
119    }
120    return true;
121  }
122
123  /**
124    @brief Event handler for the mouseMoved Event.
125    @param e Event information
126  */
127  bool InputHandlerGame::mouseMoved(const OIS::MouseEvent &e)
128  {
129    return true;
130  }
131
132  /**
133    @brief Event handler for the mousePressed Event.
134    @param e Event information
135    @param id The ID of the mouse button
136  */
137  bool InputHandlerGame::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
138  {
139    return true;
140  }
141
142  /**
143    @brief Event handler for the mouseReleased Event.
144    @param e Event information
145    @param id The ID of the mouse button
146  */
147  bool InputHandlerGame::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
148  {
149    return true;
150  }
151
152  /**
153    @brief Tick method to do additional calculations.
154    @param dt Delta time.
155  */
156  void InputHandlerGame::tick(float dt)
157  {
158    // iterate through all the pressed keys
159    for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)
160    {
161      // find the appropriate key binding
162      std::string cmdStr = bindingsKeyHold_[*it];
163      if (cmdStr != "")
164      {
165        CommandExecutor::execute(cmdStr);
166        COUT(3) << "Executing command: " << cmdStr << std::endl;
167      }
168    }
169  }
170
171  /**
172    @brief Calls all the objects from classes that derive from InputEventListener.
173    @param evt The input event that occured.
174  */
175  inline void InputHandlerGame::callListeners(orxonox::InputEvent &evt)
176  {
177    for (Iterator<InputEventListener> it = ObjectList<InputEventListener>::start(); it; )
178    {
179      if (it->bActive_)
180        (it++)->eventOccured(evt);
181      else
182        it++;
183    }
184  }
185
186
187  // ###############################
188  // ###     InputHandlerGUI     ###
189  // ###############################
190
191  /**
192    @brief standard constructor
193  */
194  InputHandlerGUI::InputHandlerGUI()
195  {
196  }
197
198  /**
199    @brief Destructor
200  */
201  InputHandlerGUI::~InputHandlerGUI()
202  {
203  }
204
205  /**
206    @brief Event handler for the keyPressed Event.
207    @param e Event information
208  */
209  bool InputHandlerGUI::keyPressed(const OIS::KeyEvent &e)
210  {
211                //CEGUI::System::getSingleton().injectKeyDown( arg.key );
212                //CEGUI::System::getSingleton().injectChar( arg.text );
213    return true;
214  }
215
216  /**
217    @brief Event handler for the keyReleased Event.
218    @param e Event information
219  */
220  bool InputHandlerGUI::keyReleased(const OIS::KeyEvent &e)
221  {
222                //CEGUI::System::getSingleton().injectKeyUp( arg.key );
223    return true;
224  }
225
226  /**
227    @brief Event handler for the mouseMoved Event.
228    @param e Event information
229  */
230  bool InputHandlerGUI::mouseMoved(const OIS::MouseEvent &e)
231  {
232                //CEGUI::System::getSingleton().injectMouseMove( arg.state.X.rel, arg.state.Y.rel );
233    return true;
234  }
235
236  /**
237    @brief Event handler for the mousePressed Event.
238    @param e Event information
239    @param id The ID of the mouse button
240  */
241  bool InputHandlerGUI::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
242  {
243                //CEGUI::System::getSingleton().injectMouseButtonDown(convertOISMouseButtonToCegui(id));
244    return true;
245  }
246
247  /**
248    @brief Event handler for the mouseReleased Event.
249    @param e Event information
250    @param id The ID of the mouse button
251  */
252  bool InputHandlerGUI::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
253  {
254                //CEGUI::System::getSingleton().injectMouseButtonUp(convertOISMouseButtonToCegui(id));
255    return true;
256  }
257
258  /**
259    @brief Tick method to do additional calculations.
260    @param dt Delta time.
261  */
262  void InputHandlerGUI::tick(float dt)
263  {
264   
265  }
266
267}
Note: See TracBrowser for help on using the repository browser.