[Orxonox-commit 757] r3286 - branches/core4/src/core/input

rgrieder at orxonox.net rgrieder at orxonox.net
Mon Jul 13 20:54:44 CEST 2009


Author: rgrieder
Date: 2009-07-13 20:54:43 +0200 (Mon, 13 Jul 2009)
New Revision: 3286

Modified:
   branches/core4/src/core/input/InputDevice.h
   branches/core4/src/core/input/InputHandler.h
   branches/core4/src/core/input/InputManager.cc
   branches/core4/src/core/input/InputManager.h
   branches/core4/src/core/input/InputPrereqs.h
   branches/core4/src/core/input/JoyStick.cc
   branches/core4/src/core/input/JoyStick.h
   branches/core4/src/core/input/JoyStickQuantityListener.cc
   branches/core4/src/core/input/JoyStickQuantityListener.h
   branches/core4/src/core/input/Keyboard.h
   branches/core4/src/core/input/Mouse.cc
   branches/core4/src/core/input/Mouse.h
Log:
Added and adjusted documentation for the devices.
Also removed one last ugliness where the InputManager was called from within a device (which should not even know about the InputManager).

Modified: branches/core4/src/core/input/InputDevice.h
===================================================================
--- branches/core4/src/core/input/InputDevice.h	2009-07-13 16:41:58 UTC (rev 3285)
+++ branches/core4/src/core/input/InputDevice.h	2009-07-13 18:54:43 UTC (rev 3286)
@@ -28,7 +28,8 @@
 
 /**
 @file
- at brief 
+ at brief
+    Implementation of InputDevice and InputDeviceTemplated
 */
 
 #ifndef _InputDevice_H__
@@ -37,67 +38,80 @@
 #include "InputPrereqs.h"
 
 #include <vector>
-#include <boost/foreach.hpp>
 #include <ois/OISInputManager.h>
 
 #include "util/Debug.h"
 #include "core/Clock.h"
-// TODO: Try to remove this
-#include "InputManager.h"
 #include "InputState.h"
 
 namespace orxonox
 {
     /**
     @brief
+        Abstract base class for all input devices (mouse, keyboard and joy sticks).
+
+        It provides common virtual functions to be used by the InputManager.
     */
     class InputDevice
     {
-        friend class InputManager;
-
     public:
-        InputDevice(unsigned int id) : bCalibrating_(false), id_(id) { }
+        //! Only resets the members
+        InputDevice(unsigned int id) : bCalibrating_(false), deviceID_(id) { }
         virtual ~InputDevice() { }
-        virtual std::string getClassName() = 0;
+        //! Returns the device class (derived) name as string
+        virtual std::string getClassName() const = 0;
+        //! Updates the device which should in turn distribute events
         virtual void update(const Clock& time) = 0;
+        //! Clear all button related buffers
         virtual void clearBuffers() = 0;
 
+        //! Start calibrating (only useful for joy sticks)
         void startCalibration()
         {
             bCalibrating_ = true;
             this->calibrationStarted();
         }
 
+        //! Stop calibrating and evaluate the data (only useful for joy sticks)
         void stopCalibration()
         {
             this->calibrationStopped();
             bCalibrating_ = false;
         }
 
-        unsigned int getDeviceID() { return this->id_; }
+        //! Returns a reference to the internal input state vector. Use with care!
+        std::vector<InputState*>& getStateListRef() { return this->inputStates_; }
+        //! Returns the ID of the device (the same as in InputDeviceEnumerator for mouse and keyboard)
+        unsigned int getDeviceID() const { return this->deviceID_; }
+        //! Tells whether the device is in calibration mode
+        bool isCalibrating() const { return bCalibrating_; }
 
     protected:
+        //! To be ovrridden by the subclass
         virtual void calibrationStarted() { }
+        //! To be ovrridden by the subclass
         virtual void calibrationStopped() { }
-        bool isCalibrating() { return bCalibrating_; }
 
-        // InputState handling
+        //! List of all input states that receive events from this device
         std::vector<InputState*> inputStates_;
 
     private:
-        InputDevice(const InputDevice& rhs);
+        InputDevice(const InputDevice& rhs); //!< Don't use!
 
-        std::vector<InputState*>& getStateListRef()
-        {
-            return this->inputStates_;
-        }
-
-        bool bCalibrating_;
-        const unsigned int id_;
+        bool bCalibrating_;                  //!< Whether the device is in calibration mode
+        const unsigned int deviceID_;        //!< ID of the device (the same as in InputDeviceEnumerator for mouse and keyboard)
     };
 
     /**
     @brief
+        Heavily templated base class for all three input devices.
+
+        The purpose of this class is not to provide an interface but rather
+        to reduce code redundancy. This concerns device creation and destruction
+        as well as common code for button events (press, release, hold).
+
+        In order to derive from this class you have to supply it with a struct
+        as template parameter that contains the necessary type traits.
     */
     template <class Traits>
     class InputDeviceTemplated : public InputDevice
@@ -109,20 +123,24 @@
         static const OIS::Type OISDeviceValue = Traits::OISDeviceValue;
 
     public:
-        InputDeviceTemplated(unsigned int id)
+        //! Creates the OIS device
+        InputDeviceTemplated(unsigned int id, OIS::InputManager* oisInputManager)
             : InputDevice(id)
+            , oisInputManager_(oisInputManager)
         {
-            OIS::InputManager* system = InputManager::getInstance().getOISInputManager();
-            oisDevice_ = static_cast<OISDeviceClass*>(system->createInputObject(OISDeviceValue, true));
+            oisDevice_ = static_cast<OISDeviceClass*>(oisInputManager_->createInputObject(OISDeviceValue, true));
+            // Note: after the static_cast here, the casted this pointer becomes
+            //       invalid right until the subclass has been constructed!
             oisDevice_->setEventCallback(static_cast<DeviceClass*>(this));
             COUT(4) << "Instantiated a " << this->getClassName() << std::endl;
         }
 
+        //! Destroys the OIS device
         virtual ~InputDeviceTemplated()
         {
             try
             {
-                InputManager::getInstance().getOISInputManager()->destroyInputObject(oisDevice_);
+                oisInputManager_->destroyInputObject(oisDevice_);
             }
             catch (...)
             {
@@ -130,43 +148,38 @@
             }
         }
 
-        OISDeviceClass* getOISDevice()
-        {
-            return this->oisDevice_;
-        }
-
-        std::string getClassName()
-        {
-            return DeviceClass::getClassNameImpl();
-        }
-
+        //! Captures OIS events (which then get distributed to the derived class) and creates the button held events
         void update(const Clock& time)
         {
             oisDevice_->capture();
 
-            if (!this->isCalibrating())
-            {
-                // Call all the states with the held button event
-                for (unsigned int iB = 0; iB < pressedButtons_.size(); ++iB)
-                    for (unsigned int iS = 0; iS < inputStates_.size(); ++iS)
-                        inputStates_[iS]->buttonEvent<ButtonEvent::THold, Traits>(
-                            this->getDeviceID(), static_cast<DeviceClass*>(this)->getButtonEventArg(pressedButtons_[iB]));
+            // Call all the states with the held button event
+            for (unsigned int iB = 0; iB < pressedButtons_.size(); ++iB)
+                for (unsigned int iS = 0; iS < inputStates_.size(); ++iS)
+                    inputStates_[iS]->buttonEvent<ButtonEvent::THold, Traits>(
+                        this->getDeviceID(), static_cast<DeviceClass*>(this)->getButtonEventArg(pressedButtons_[iB]));
 
-                // Call states with device update events
-                for (unsigned int i = 0; i < inputStates_.size(); ++i)
-                    inputStates_[i]->update(time.getDeltaTime(), this->getDeviceID());
-            }
+            // Call states with device update events
+            for (unsigned int i = 0; i < inputStates_.size(); ++i)
+                inputStates_[i]->update(time.getDeltaTime(), this->getDeviceID());
 
             static_cast<DeviceClass*>(this)->updateImpl(time);
         }
 
+        //! Clears the list of pressed buttons and calls the derived class's method
         void clearBuffers()
         {
             pressedButtons_.clear();
             static_cast<DeviceClass*>(this)->clearBuffersImpl();
         }
 
+        // Returns a pointer to the OIS device
+        OISDeviceClass* getOISDevice()   { return this->oisDevice_; }
+        // Returns the name of the derived class as string
+        std::string getClassName() const { return DeviceClass::getClassNameImpl(); }
+
     protected:
+        //! Common code for all button pressed events (updates pressed buttons list and calls the input states)
         void buttonPressed(ButtonTypeParam button)
         {
             // check whether the button already is in the list (can happen when focus was lost)
@@ -183,6 +196,7 @@
                 inputStates_[i]->buttonEvent<ButtonEvent::TPress, Traits>(this->getDeviceID(), static_cast<DeviceClass*>(this)->getButtonEventArg(button));
         }
 
+        //! Common code for all button released events (updates pressed buttons list and calls the input states)
         void buttonReleased(ButtonTypeParam button)
         {
             // remove the button from the pressedButtons_ list
@@ -200,15 +214,19 @@
                 inputStates_[i]->buttonEvent<ButtonEvent::TRelease, Traits>(this->getDeviceID(), static_cast<DeviceClass*>(this)->getButtonEventArg(button));
         }
 
+        //! Managed pointer to the OIS device
         OISDeviceClass* oisDevice_;
 
     private:
-        void clearBuffersImpl() { } //!< Fallback dummy function for static polymorphism
-        void updateImpl(const Clock& time) { } //!< Fallback dummy function for static polymorphism
         //!< Fallback dummy function for static polymorphism
+        void clearBuffersImpl() { }
+        //!< Fallback dummy function for static polymorphism
+        void updateImpl(const Clock& time) { }
+        //!< Fallback dummy function for static polymorphism
         ButtonType& getButtonEventArg(ButtonType& button) { return button; }
 
-        std::vector<ButtonType> pressedButtons_;
+        std::vector<ButtonType> pressedButtons_; //!< List of all buttons that are currently pressed down
+        OIS::InputManager* oisInputManager_;     //!< Pointer to the OIS InputManager that can create and destroy devices
     };
 }
 

Modified: branches/core4/src/core/input/InputHandler.h
===================================================================
--- branches/core4/src/core/input/InputHandler.h	2009-07-13 16:41:58 UTC (rev 3285)
+++ branches/core4/src/core/input/InputHandler.h	2009-07-13 18:54:43 UTC (rev 3286)
@@ -26,12 +26,6 @@
  *
  */
 
-/**
- at file
- at brief
-    Declarations of various interface classes for the input management.
-*/
-
 #ifndef _InputHandler_H__
 #define _InputHandler_H__
 
@@ -99,6 +93,13 @@
 
     /**
     @brief
+        Base class for all input handlers like KeyBinder, InputBuffer, etc.
+
+        Derive from this class if you wish to receive input events.
+        But keep in mind that this is pointless wihtout first having an InputState.
+    @note
+        The definitions for the button events with the weird arguments are simply
+        to avoid redunant code in the input devices.
     */
     class _CoreExport InputHandler
     {
@@ -139,6 +140,7 @@
 
         virtual void allDevicesUpdated(float dt) { }
 
+        //! Use this input handler if you want to occupy a device in an input state.
         static InputHandler EMPTY;
     };
 }

Modified: branches/core4/src/core/input/InputManager.cc
===================================================================
--- branches/core4/src/core/input/InputManager.cc	2009-07-13 16:41:58 UTC (rev 3285)
+++ branches/core4/src/core/input/InputManager.cc	2009-07-13 18:54:43 UTC (rev 3286)
@@ -200,7 +200,7 @@
             CCOUT(ORX_DEBUG) << "Created OIS input manager." << std::endl;
 
             if (oisInputManager_->getNumberOfDevices(OIS::OISKeyboard) > 0)
-                devices_[InputDeviceEnumerator::Keyboard] = new Keyboard(InputDeviceEnumerator::Keyboard);
+                devices_[InputDeviceEnumerator::Keyboard] = new Keyboard(InputDeviceEnumerator::Keyboard, oisInputManager_);
             else
                 ThrowException(InitialisationFailed, "InputManager: No keyboard found, cannot proceed!");
 
@@ -231,7 +231,7 @@
         {
             try
             {
-                devices_[InputDeviceEnumerator::Mouse] = new Mouse(InputDeviceEnumerator::Mouse, windowWidth, windowHeight);
+                devices_[InputDeviceEnumerator::Mouse] = new Mouse(InputDeviceEnumerator::Mouse, oisInputManager_, windowWidth, windowHeight);
             }
             catch (const OIS::Exception& ex)
             {
@@ -250,7 +250,7 @@
         {
             try
             {
-                devices_.push_back(new JoyStick(InputDeviceEnumerator::FirstJoyStick + i));
+                devices_.push_back(new JoyStick(InputDeviceEnumerator::FirstJoyStick + i, oisInputManager_));
             }
             catch (std::exception ex)
             {
@@ -263,14 +263,6 @@
             it->JoyStickQuantityChanged(devices_.size() - InputDeviceEnumerator::FirstJoyStick);
     }
 
-    bool InputManager::checkJoyStickID(const std::string& idString) const
-    {
-        for (unsigned int i = InputDeviceEnumerator::FirstJoyStick; i < devices_.size(); ++i)
-            if (static_cast<JoyStick*>(devices_[i])->getIDString() == idString)
-                return false;
-        return true;
-    }
-
     void InputManager::setKeyDetectorCallback(const std::string& command)
     {
         this->keyDetector_->setCallbackCommand(command);
@@ -564,6 +556,8 @@
         internalState_ &= ~Calibrating;
         // Clear buffers to prevent button hold events
         this->clearBuffers();
+
+        COUT(0) << "Calibration has been stored." << std::endl;
     }
 
     // ############################################################

Modified: branches/core4/src/core/input/InputManager.h
===================================================================
--- branches/core4/src/core/input/InputManager.h	2009-07-13 16:41:58 UTC (rev 3285)
+++ branches/core4/src/core/input/InputManager.h	2009-07-13 18:54:43 UTC (rev 3286)
@@ -160,13 +160,6 @@
         //-------------------------------
         //! Sets the the name of the command used by the KeyDetector as callback.
         void setKeyDetectorCallback(const std::string& command);
-        /**
-        @brief
-            Checks whether there is already a joy stick with the given ID string.
-        @return
-            Returns true if ID is ok (unique), false otherwise.
-        */
-        bool checkJoyStickID(const std::string& idString) const;
         //! Returns the number of joy stick that have been created since the c'tor or last call to reload().
         unsigned int getJoyStickQuantity() const
             { return devices_.size() - InputDeviceEnumerator::FirstJoyStick; }

Modified: branches/core4/src/core/input/InputPrereqs.h
===================================================================
--- branches/core4/src/core/input/InputPrereqs.h	2009-07-13 16:41:58 UTC (rev 3285)
+++ branches/core4/src/core/input/InputPrereqs.h	2009-07-13 18:54:43 UTC (rev 3286)
@@ -29,7 +29,8 @@
 /**
 @file
 @brief
-    Declarations of various interface classes for the input management.
+    Declarations of all key/button/axis code enumeration and string literals
+    and an input device enumeration.
 */
 
 #ifndef _InputPrereqs_H__
@@ -51,7 +52,7 @@
     {
         const unsigned int numberOfKeys = 0xEE; // 238
 
-        // note: KeyCode comments were directly copied from OISKeyboard.h
+        //! Key codes as enumeration
         enum ByEnum
         {
             Unassigned    = OIS::KC_UNASSIGNED,
@@ -201,7 +202,7 @@
             MediaSelect   = OIS::KC_MEDIASELECT      // Media Select
         };
         
-        // Names as string. Has no real linkage!
+        //! Key codes as strings
         const char* const ByString[] =
         {
             "Unassigned",
@@ -306,6 +307,7 @@
     {
         const unsigned int numberOfButtons = 8;
 
+        //! Mouse button codes as enumeration
         enum ByEnum
         {
             Left    = OIS::MB_Left,
@@ -318,7 +320,7 @@
             Button7 = OIS::MB_Button7,
         };
 
-        // Names as string. Has no real linkage!
+        // Mouse button codes as strings
         const char* const ByString[] =
         {
             "Left",
@@ -336,13 +338,14 @@
     {
         const unsigned int numberOfAxes = 2;
 
+        // Mouse axis codes as enumeration
         enum ByEnum
         {
             X,
             Y
         };
 
-        // Names as string. Has no real linkage!
+        // Mouse axis codes as strings
         const char* const ByString[] =
         {
             "X",
@@ -355,6 +358,7 @@
     {
         const unsigned int numberOfButtons = 64;
 
+        // Joy stick button codes as enumeration
         enum ByEnum
         {
             Button0       =  0, Button1       =  1, Button2       =  2, Button3       =  3,
@@ -379,7 +383,7 @@
             POV3NorthEast = 60, POV3SouthEast = 61, POV3NorthWest = 62, POV3SouthWest = 63,
         };
 
-        // Names as string. Has no real linkage!
+        // Joy stick button codes as strings
         const char* const ByString[] =
         {
             "Button00",      "Button01",      "Button02",      "Button03",
@@ -405,6 +409,7 @@
     {
         const unsigned int numberOfAxes = 24;
 
+        // Joy stick axis codes as enumeration
         enum ByEnum
         {
             Slider0 =  0, Slider1 =  1, Slider2 =  2, Slider3 =  3,
@@ -415,7 +420,7 @@
             Axis12  = 20, Axis13  = 21, Axis14  = 22, Axis15  = 23
         };
 
-        // Names as string. Has no real linkage!
+        // Joy stick axis codes as strings
         const char* const ByString[] =
         {
             "Slider0", "Slider1", "Slider2", "Slider3",
@@ -434,6 +439,7 @@
 
     namespace InputDeviceEnumerator
     {
+        //! Used to access the devices in an array
         enum Value
         {
             Keyboard = 0,

Modified: branches/core4/src/core/input/JoyStick.cc
===================================================================
--- branches/core4/src/core/input/JoyStick.cc	2009-07-13 16:41:58 UTC (rev 3285)
+++ branches/core4/src/core/input/JoyStick.cc	2009-07-13 18:54:43 UTC (rev 3286)
@@ -29,7 +29,6 @@
 #include "JoyStick.h"
 
 #include <ois/OISJoyStick.h>
-#include <ois/OISInputManager.h>
 #include <boost/foreach.hpp>
 
 #include "core/ConfigFileManager.h"
@@ -37,18 +36,16 @@
 #include "core/CoreIncludes.h"
 #include "util/Convert.h"
 #include "InputState.h"
-#include "InputManager.h"
 
 namespace orxonox
 {
-    /**
-    @brief
-        Helper function that loads the config value vector of one coefficient
-    */
+    //! Helper function that loads the config value vector of one coefficient
     void loadCalibration(std::vector<int>& list, const std::string& sectionName, const std::string& valueName, size_t size, int defaultValue);
 
-    JoyStick::JoyStick(unsigned int id)
-        : super(id)
+    std::vector<std::string> JoyStick::idStrings_s;
+
+    JoyStick::JoyStick(unsigned int id, OIS::InputManager* oisInputManager)
+        : super(id, oisInputManager)
     {
         RegisterRootObject(JoyStick);
         this->setConfigValues();
@@ -65,10 +62,15 @@
         idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_POV));
         //idString_ += multi_cast<std::string>(oisDevice_->getNumberOfComponents(OIS::OIS_Vector3));
 
-        if (InputManager::getInstance().checkJoyStickID(idString_) == false)
+
+        BOOST_FOREACH(std::string& idString, idStrings_s)
         {
-            // Make the ID unique for this execution time.
-            idString_ += "_" + multi_cast<std::string>(this->getDeviceID());
+            if (idString_ == idString)
+            {
+                // Make the ID unique for this execution time.
+                idString_ += "_" + multi_cast<std::string>(this->getDeviceID());
+                break;
+            }
         }
 
         COUT(4) << "Created OIS joy stick with ID " << idString_ << std::endl;
@@ -81,7 +83,7 @@
         this->evaluateCalibration();
     }
 
-    //!< Callback for the joy stick calibration config file.
+    //! Callback for the joy stick calibration config file.
     void JoyStick::calibrationFileCallback()
     {
         ConfigFileManager::getInstance().setFilename(ConfigFileType::JoyStickCalibration, calibrationFilename_);
@@ -172,15 +174,11 @@
         }
     }
 
-    // TODO: What do we really need to reset here?
+    //! Resets the pov states
     void JoyStick::clearBuffersImpl()
     {
         for (int j = 0; j < 4; ++j)
-        {
             povStates_[j] = 0;
-            sliderStates_[j][0] = 0;
-            sliderStates_[j][1] = 0;
-        }
     }
 
     //! Generic method to forward axis events

Modified: branches/core4/src/core/input/JoyStick.h
===================================================================
--- branches/core4/src/core/input/JoyStick.h	2009-07-13 16:41:58 UTC (rev 3285)
+++ branches/core4/src/core/input/JoyStick.h	2009-07-13 18:54:43 UTC (rev 3286)
@@ -37,6 +37,7 @@
 
 namespace orxonox
 {
+    //! Template parameter collection for the base class
     struct JoyStickTraits
     {
         typedef JoyStick DeviceClass;
@@ -65,11 +66,11 @@
 
     public:
         //! Assigns a generated ID string and loads the calibration (if present)
-        JoyStick(unsigned int id);
+        JoyStick(unsigned int id, OIS::InputManager* oisInputManager);
         ~JoyStick() { }
         void setConfigValues();
 
-        //! Returns the generated (from the number of knobs and the device name) ID string
+        //! Returns the ID string generated from the number of knobs and the device name
         const std::string& getIDString() const { return this->idString_; }
 
     private:
@@ -98,9 +99,10 @@
         bool axisMoved     (const OIS::JoyStickEvent &arg, int axis);
         bool sliderMoved   (const OIS::JoyStickEvent &arg, int id);
         bool povMoved      (const OIS::JoyStickEvent &arg, int id);
-        //!< OIS event handler (don't remove that because of OIS version issues!)
+        //! OIS event handler (don't remove that because of OIS version issues!)
         bool vector3Moved  (const OIS::JoyStickEvent &arg, int id) { return true; }
 
+        //! Returns the class name as string
         static std::string getClassNameImpl() { return "JoyStick"; }
 
         std::string idString_;                //!< ID string generated by the number of knobs and the device name
@@ -119,6 +121,9 @@
         // ConfigValues
         std::string calibrationFilename_;     //!< Joy stick calibration ini filename
 
+        //! Contains a list of all ID strings to avoid duplicates
+        static std::vector<std::string> idStrings_s;
+
         //!< Maximum number of slider axes
         static const unsigned int sliderAxes_s = 8;
     };

Modified: branches/core4/src/core/input/JoyStickQuantityListener.cc
===================================================================
--- branches/core4/src/core/input/JoyStickQuantityListener.cc	2009-07-13 16:41:58 UTC (rev 3285)
+++ branches/core4/src/core/input/JoyStickQuantityListener.cc	2009-07-13 18:54:43 UTC (rev 3286)
@@ -26,12 +26,6 @@
  *
  */
 
-/**
- at file
- at brief
-    Implementation of the JoyStickQuantityListener class.
-*/
-
 #include "JoyStickQuantityListener.h"
 #include "core/CoreIncludes.h"
 

Modified: branches/core4/src/core/input/JoyStickQuantityListener.h
===================================================================
--- branches/core4/src/core/input/JoyStickQuantityListener.h	2009-07-13 16:41:58 UTC (rev 3285)
+++ branches/core4/src/core/input/JoyStickQuantityListener.h	2009-07-13 18:54:43 UTC (rev 3286)
@@ -39,12 +39,14 @@
 
 namespace orxonox
 {
+    //! Derive from this class to get informed when joy sticks get added/removed
     class _CoreExport JoyStickQuantityListener : virtual public OrxonoxClass
     {
     public:
         JoyStickQuantityListener();
         virtual ~JoyStickQuantityListener() { }
 
+        //! Called when joy sticks get added/removed
         virtual void JoyStickQuantityChanged(unsigned int value) = 0;
     };
 }

Modified: branches/core4/src/core/input/Keyboard.h
===================================================================
--- branches/core4/src/core/input/Keyboard.h	2009-07-13 16:41:58 UTC (rev 3285)
+++ branches/core4/src/core/input/Keyboard.h	2009-07-13 18:54:43 UTC (rev 3286)
@@ -30,11 +30,13 @@
 #define _Core_Keyboard_H__
 
 #include "InputPrereqs.h"
+
 #include "InputHandler.h"
 #include "InputDevice.h"
 
 namespace orxonox
 {
+    //! Template parameter collection for the base class
     struct KeyboardTraits
     {
         typedef Keyboard DeviceClass;
@@ -60,18 +62,24 @@
         typedef InputDeviceTemplated<KeyboardTraits> super;
 
     public:
-        Keyboard(unsigned int id) : super(id), modifiers_(0) { }
+        //! Only resets the keyboard modifiers. Initialising is done in the base class.
+        Keyboard(unsigned int id, OIS::InputManager* oisInputManager) : super(id, oisInputManager), modifiers_(0) { }
         ~Keyboard() { }
 
     private:
-        // TODO: Do we need to reset the modifiers?
-        void clearBuffersImpl() { }
+        //! Resets the keyboard modifiers
+        void clearBuffersImpl() { this->modifiers_ = 0; }
         //! Translates the KeyHandle to a KeyEvent
-        KeyEvent& getButtonEventArg(KeyEvent& button) { button.setModifiers(modifiers_); return button; }
+        KeyEvent& getButtonEventArg(KeyEvent& button)
+        {
+            button.setModifiers(modifiers_);
+            return button;
+        }
 
         bool keyPressed(const OIS::KeyEvent& arg);
         bool keyReleased(const OIS::KeyEvent& arg);
 
+        //! Returns the class name as string
         static std::string getClassNameImpl() { return "Keyboard"; }
 
         //! Bit mask representing keyboard modifiers

Modified: branches/core4/src/core/input/Mouse.cc
===================================================================
--- branches/core4/src/core/input/Mouse.cc	2009-07-13 16:41:58 UTC (rev 3285)
+++ branches/core4/src/core/input/Mouse.cc	2009-07-13 18:54:43 UTC (rev 3286)
@@ -29,7 +29,6 @@
 #include "Mouse.h"
 
 #include <ois/OISMouse.h>
-#include <boost/foreach.hpp>
 #include "InputState.h"
 #include "core/ConsoleCommand.h"
 
@@ -40,8 +39,8 @@
 
 namespace orxonox
 {
-    Mouse::Mouse(unsigned int id, unsigned int windowWidth, unsigned int windowHeight)
-        : super(id)
+    Mouse::Mouse(unsigned int id, OIS::InputManager* oisInputManager, unsigned int windowWidth, unsigned int windowHeight)
+        : super(id, oisInputManager)
     {
         this->setMouseClipping(windowWidth, windowHeight);
         // HACK:
@@ -73,15 +72,15 @@
             IntVector2 abs(e.state.X.abs, e.state.Y.abs);
             IntVector2 rel(e.state.X.rel, e.state.Y.rel);
             IntVector2 clippingSize(e.state.width, e.state.height);
-            BOOST_FOREACH(InputState* state, inputStates_)
-                state->mouseMoved(abs, rel, clippingSize);
+            for (unsigned int i = 0; i < inputStates_.size(); ++i)
+                inputStates_[i]->mouseMoved(abs, rel, clippingSize);
         }
 
         // check for mouse scrolled event
         if (e.state.Z.rel != 0)
         {
-            BOOST_FOREACH(InputState* state, inputStates_)
-                state->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
+            for (unsigned int i = 0; i < inputStates_.size(); ++i)
+                inputStates_[i]->mouseScrolled(e.state.Z.abs, e.state.Z.rel);
         }
 
         return true;

Modified: branches/core4/src/core/input/Mouse.h
===================================================================
--- branches/core4/src/core/input/Mouse.h	2009-07-13 16:41:58 UTC (rev 3285)
+++ branches/core4/src/core/input/Mouse.h	2009-07-13 18:54:43 UTC (rev 3286)
@@ -34,6 +34,7 @@
 
 namespace orxonox
 {
+    //! Template parameter collection for the base class
     struct MouseTraits
     {
         typedef Mouse DeviceClass;
@@ -57,7 +58,8 @@
         typedef InputDeviceTemplated<MouseTraits> super;
 
     public:
-        Mouse(unsigned int id, unsigned int windowWidth, unsigned int windowHeight);
+        //! Only sets the clipping size. Initialising is done in the base class.
+        Mouse(unsigned int id, OIS::InputManager* oisInputManager, unsigned int windowWidth, unsigned int windowHeight);
         ~Mouse() { }
 
         /**
@@ -67,7 +69,9 @@
             This method has to be called every time the size of the window changes.
         */
         void setMouseClipping(unsigned int width, unsigned int height);
+        // Returns the width of the mouse window
         unsigned int getClippingWidth() const;
+        // Returns the height of the mouse window
         unsigned int getClippingHeight() const;
 
         // HACK!
@@ -76,14 +80,12 @@
         void setConfigValues() { }
 #ifdef ORXONOX_PLATFORM_LINUX
         // HACK!
+        // TODO: Make this a feature rather than a hack
         static void grabMouse();
         static void ungrabMouse();
 #endif
 
     private:
-        // TODO: Do we need to reset the mouse position?
-        void clearBuffersImpl() { }
-
         //! OIS event handler
         bool mousePressed(const OIS::MouseEvent &arg, OIS::MouseButtonID id)
         {
@@ -100,6 +102,7 @@
 
         bool mouseMoved(const OIS::MouseEvent &arg);
 
+        // Returns the class name as string
         static std::string getClassNameImpl() { return "Mouse"; }
 
         // HACK:




More information about the Orxonox-commit mailing list