Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/orxonox/InputHandler.cc @ 919

Last change on this file since 919 was 919, checked in by rgrieder, 16 years ago
  • AudioManager is now Tickable
  • NPC update moved to its tick-function
  • corrected CMakeLists
  • added a few window properties to GraphicsEngine
  • OrxListener has been completely replaced
File size: 5.6 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *
4 *
5 *   License notice:
6 *
7 *   This program is free software; you can redistribute it and/or
8 *   modify it under the terms of the GNU General Public License
9 *   as published by the Free Software Foundation; either version 2
10 *   of the License, or (at your option) any later version.
11 *
12 *   This program is distributed in the hope that it will be useful,
13 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
14 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 *   GNU General Public License for more details.
16 *
17 *   You should have received a copy of the GNU General Public License
18 *   along with this program; if not, write to the Free Software
19 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20 *
21 *   Author:
22 *      Reto Grieder
23 *   Co-authors:
24 *      Some guy writing the example code from Ogre
25 *
26 */
27
28/**
29 @file
30 @brief Implementation of a little Input handler that distributes everything
31        coming from OIS.
32 */
33
34#include "OrxonoxStableHeaders.h"
35
36#include "Orxonox.h"
37#include "InputHandler.h"
38
39namespace orxonox
40{
41  //using namespace OIS;
42
43  /**
44    @brief Constructor only resets the pointer values to 0.
45  */
46  InputHandler::InputHandler()
47  {
48    /*if (orxonox::Identifier::isCreatingHierarchy() && !this->getParents())
49        this->createParents();
50    this->setIdentifier(orxonox::ClassManager<InputHandler>::getIdentifier()->registerClass(this->getParents(), "InputHandler", true));
51    if (orxonox::Identifier::isCreatingHierarchy() && this->getParents())
52        this->getParents()->insert(this->getParents()->end(), this->getIdentifier());
53    orxonox::ClassManager<InputHandler>::getIdentifier()->addObject(this);*/
54
55    //RegisterObject(InputHandler);
56
57    this->mouse_       = 0;
58    this->keyboard_    = 0;
59    this->inputSystem_ = 0;
60
61    //this->setConfigValues();
62  }
63
64  void InputHandler::setConfigValues()
65  {
66    //SetConfigValue(codeFire_, 4).description("test value");
67
68    ConfigValueContainer *containercodeFire_ = new ConfigValueContainer("asdfblah", "codeFire_", 4);
69    containercodeFire_->getValue(&codeFire_).description("test");
70    //containercodeFire_->
71  }
72
73  /**
74    @brief The one instance of the InputHandler is stored in this function.
75    @return The pointer to the only instance of the InputHandler
76  */
77  InputHandler* InputHandler::getSingleton()
78  {
79    static InputHandler theOnlyInstance;
80    return &theOnlyInstance;
81  }
82
83  /**
84    @brief Creates the OIS::InputMananger, the keyboard and the mouse
85    @param windowHnd The window handle of the render window
86    @param windowWidth The width of the render window
87    @param windowHeight The height of the render window
88  */
89  void InputHandler::initialise(size_t windowHnd, int windowWidth, int windowHeight)
90  {
91    if (!inputSystem_)
92    {
93      // Setup basic variables
94      OIS::ParamList paramList;
95      std::ostringstream windowHndStr;
96
97      // Fill parameter list
98      windowHndStr << (unsigned int)windowHnd;
99      paramList.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str()));
100
101      // Create inputsystem
102      inputSystem_ = OIS::InputManager::createInputSystem(paramList);
103
104      // If possible create a buffered keyboard
105      if (inputSystem_->numKeyboards() > 0)
106      {
107        keyboard_ = static_cast<OIS::Keyboard*>(inputSystem_->createInputObject(OIS::OISKeyboard, true));
108        keyboard_->setEventCallback(this);
109      }
110
111      // If possible create a buffered mouse
112      if (inputSystem_->numMice() > 0 )
113      {
114        mouse_ = static_cast<OIS::Mouse*>(inputSystem_->createInputObject(OIS::OISMouse, true));
115        mouse_->setEventCallback(this);
116
117        // Set mouse region
118        this->setWindowExtents(windowWidth, windowHeight);
119      }
120    }
121  }
122
123  /**
124    @brief Updates the InputHandler
125    @param dt Delta time
126  */
127  void InputHandler::tick(float dt)
128  {
129    // capture all the input. That calls the event handlers.
130    if (mouse_)
131    {
132      mouse_->capture();
133    }
134
135    if (keyboard_)
136    {
137      keyboard_->capture();
138    }
139  }
140
141  /**
142    @brief Adjusts the mouse window metrics.
143    This method has to be called every time the size of the window changes.
144    @param width The new width of the render window
145    @param height the new height of the render window
146  */
147  void InputHandler::setWindowExtents(int width, int height)
148  {
149    // Set mouse region (if window resizes, we should alter this to reflect as well)
150    const OIS::MouseState &mouseState = mouse_->getMouseState();
151    mouseState.width  = width;
152    mouseState.height = height;
153  }
154
155  /**
156    @brief Event handler for the keyPressed Event.
157    @param e Event information
158  */
159  bool InputHandler::keyPressed(const OIS::KeyEvent &e)
160  {
161    if (e.key == OIS::KC_ESCAPE)
162      Orxonox::getSingleton()->abortRequest();
163    return true;
164  }
165
166  /**
167    @brief Event handler for the keyReleased Event.
168    @param e Event information
169  */
170  bool InputHandler::keyReleased(const OIS::KeyEvent &e)
171  {
172    return true;
173  }
174
175  /**
176    @brief Event handler for the mouseMoved Event.
177    @param e Event information
178  */
179  bool InputHandler::mouseMoved(const OIS::MouseEvent &e)
180  {
181    return true;
182  }
183
184  /**
185    @brief Event handler for the mousePressed Event.
186    @param e Event information
187    @param id The ID of the mouse button
188  */
189  bool InputHandler::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
190  {
191    return true;
192  }
193
194  /**
195    @brief Event handler for the mouseReleased Event.
196    @param e Event information
197    @param id The ID of the mouse button
198  */
199  bool InputHandler::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
200  {
201    return true;
202  }
203
204}
Note: See TracBrowser for help on using the repository browser.