[Orxonox-commit 756] r3285 - branches/core4/src/core/input

rgrieder at orxonox.net rgrieder at orxonox.net
Mon Jul 13 18:41:58 CEST 2009


Author: rgrieder
Date: 2009-07-13 18:41:58 +0200 (Mon, 13 Jul 2009)
New Revision: 3285

Modified:
   branches/core4/src/core/input/InputDevice.h
   branches/core4/src/core/input/InputHandler.h
   branches/core4/src/core/input/InputPrereqs.h
   branches/core4/src/core/input/JoyStick.h
   branches/core4/src/core/input/Keyboard.h
   branches/core4/src/core/input/Mouse.h
Log:
Shoved some code around to reduce contents of 'global' InputPrereqs.h

Modified: branches/core4/src/core/input/InputDevice.h
===================================================================
--- branches/core4/src/core/input/InputDevice.h	2009-07-13 16:03:24 UTC (rev 3284)
+++ branches/core4/src/core/input/InputDevice.h	2009-07-13 16:41:58 UTC (rev 3285)
@@ -137,7 +137,7 @@
 
         std::string getClassName()
         {
-            return InputDeviceNames::values[OISDeviceValue];
+            return DeviceClass::getClassNameImpl();
         }
 
         void update(const Clock& time)

Modified: branches/core4/src/core/input/InputHandler.h
===================================================================
--- branches/core4/src/core/input/InputHandler.h	2009-07-13 16:03:24 UTC (rev 3284)
+++ branches/core4/src/core/input/InputHandler.h	2009-07-13 16:41:58 UTC (rev 3285)
@@ -40,6 +40,63 @@
 
 namespace orxonox
 {
+    namespace ButtonEvent
+    {
+        //! Helper enum to deploy events with the help of templates
+        enum Value
+        {
+            Press,
+            Release,
+            Hold
+        };
+
+        //! Enables function overloading with integer values
+        template <ButtonEvent::Value Event>
+        struct EnumToType { };
+        typedef EnumToType<Press>   TPress;
+        typedef EnumToType<Release> TRelease;
+        typedef EnumToType<Hold>    THold;
+    }
+
+    namespace KeyboardModifier
+    {
+        //! Keyboard modifiers (shift, ctrl and alt)
+        enum Enum
+        {
+            Shift = 0x0000001,
+            Ctrl  = 0x0000010,
+            Alt   = 0x0000100
+        };
+    }
+
+    //! Event argument for key events
+    class _CoreExport KeyEvent
+    {
+    public:
+        KeyEvent(const OIS::KeyEvent& evt)
+            : key_(static_cast<KeyCode::ByEnum>(evt.key))
+            , text_(evt.text)
+            , modifiers_(0)
+        { }
+        bool operator==(const KeyEvent& rhs) const
+            { return rhs.key_ == key_; }
+        bool operator!=(const KeyEvent& rhs) const
+            { return rhs.key_ != key_; }
+        void setModifiers(int modifiers)
+            { modifiers_ = modifiers; }
+
+        bool isModifierDown(KeyboardModifier::Enum modifier) const
+            { return static_cast<KeyboardModifier::Enum>(modifier & modifiers_); }
+        KeyCode::ByEnum getKeyCode() const
+            { return key_; }
+        unsigned int getText() const { return text_; }
+
+    private:
+        KeyCode::ByEnum key_;
+        unsigned int text_;
+        int modifiers_;
+    };
+
     /**
     @brief
     */

Modified: branches/core4/src/core/input/InputPrereqs.h
===================================================================
--- branches/core4/src/core/input/InputPrereqs.h	2009-07-13 16:03:24 UTC (rev 3284)
+++ branches/core4/src/core/input/InputPrereqs.h	2009-07-13 16:41:58 UTC (rev 3285)
@@ -441,98 +441,6 @@
             FirstJoyStick = 2
         };
     }
-
-    namespace ButtonEvent
-    {
-        enum Value
-        {
-            Press,
-            Release,
-            Hold
-        };
-
-        template <ButtonEvent::Value Event>
-        struct EnumToType { };
-        typedef EnumToType<Press>   TPress;
-        typedef EnumToType<Release> TRelease;
-        typedef EnumToType<Hold>    THold;
-    }
-
-
-    namespace KeyboardModifier
-    {
-        enum Enum
-        {
-            Shift = 0x0000001,
-            Ctrl  = 0x0000010,
-            Alt   = 0x0000100
-        };
-    }
-
-    class _CoreExport KeyEvent
-    {
-    public:
-        KeyEvent(const OIS::KeyEvent& evt)
-            : key_(static_cast<KeyCode::ByEnum>(evt.key))
-            , text_(evt.text)
-            , modifiers_(0)
-        { }
-        bool operator==(const KeyEvent& rhs) const
-            { return rhs.key_ == key_; }
-        bool operator!=(const KeyEvent& rhs) const
-            { return rhs.key_ != key_; }
-        void setModifiers(int modifiers)
-            { modifiers_ = modifiers; }
-
-        bool isModifierDown(KeyboardModifier::Enum modifier) const
-            { return static_cast<KeyboardModifier::Enum>(modifier & modifiers_); }
-        KeyCode::ByEnum getKeyCode() const
-            { return key_; }
-        unsigned int getText() const { return text_; }
-
-    private:
-        KeyCode::ByEnum key_;
-        unsigned int text_;
-        int modifiers_;
-    };
-
-
-    //-----------------------------------------------------------------------
-    // Device type traits
-    //-----------------------------------------------------------------------
-
-    struct KeyboardTraits
-    {
-        typedef Keyboard DeviceClass;
-        typedef OIS::Keyboard OISDeviceClass;
-        typedef KeyEvent ButtonType;
-        typedef KeyEvent& ButtonTypeParam;
-        static const OIS::Type OISDeviceValue = OIS::OISKeyboard;
-    };
-
-    struct MouseTraits
-    {
-        typedef Mouse DeviceClass;
-        typedef OIS::Mouse OISDeviceClass;
-        typedef MouseButtonCode::ByEnum ButtonType;
-        typedef MouseButtonCode::ByEnum ButtonTypeParam;
-        static const OIS::Type OISDeviceValue = OIS::OISMouse;
-    };
-
-    struct JoyStickTraits
-    {
-        typedef JoyStick DeviceClass;
-        typedef OIS::JoyStick OISDeviceClass;
-        typedef JoyStickButtonCode::ByEnum ButtonType;
-        typedef JoyStickButtonCode::ByEnum ButtonTypeParam;
-        static const OIS::Type OISDeviceValue = OIS::OISJoyStick;
-    };
-
-    // Note: Entries correspond to OIS::Type enum
-    namespace InputDeviceNames
-    {
-        const char* const values[] = { "", "Keyboard", "Mouse", "JoyStick" };
-    }
 }
 
 #endif /* _InputPrereqs_H__ */

Modified: branches/core4/src/core/input/JoyStick.h
===================================================================
--- branches/core4/src/core/input/JoyStick.h	2009-07-13 16:03:24 UTC (rev 3284)
+++ branches/core4/src/core/input/JoyStick.h	2009-07-13 16:41:58 UTC (rev 3285)
@@ -37,6 +37,15 @@
 
 namespace orxonox
 {
+    struct JoyStickTraits
+    {
+        typedef JoyStick DeviceClass;
+        typedef OIS::JoyStick OISDeviceClass;
+        typedef JoyStickButtonCode::ByEnum ButtonType;
+        typedef JoyStickButtonCode::ByEnum ButtonTypeParam;
+        static const OIS::Type OISDeviceValue = OIS::OISJoyStick;
+    };
+
     /**
     @brief
         Wraps around an OIS::JoyStick and forwards the input events to
@@ -92,6 +101,8 @@
         //!< OIS event handler (don't remove that because of OIS version issues!)
         bool vector3Moved  (const OIS::JoyStickEvent &arg, int id) { return true; }
 
+        static std::string getClassNameImpl() { return "JoyStick"; }
+
         std::string idString_;                //!< ID string generated by the number of knobs and the device name
         int povStates_[4];                    //!< Internal states for the POVs
         int sliderStates_[4][2];              //!< Internal states for the Sliders (each slider has X and Y!)

Modified: branches/core4/src/core/input/Keyboard.h
===================================================================
--- branches/core4/src/core/input/Keyboard.h	2009-07-13 16:03:24 UTC (rev 3284)
+++ branches/core4/src/core/input/Keyboard.h	2009-07-13 16:41:58 UTC (rev 3285)
@@ -30,10 +30,20 @@
 #define _Core_Keyboard_H__
 
 #include "InputPrereqs.h"
+#include "InputHandler.h"
 #include "InputDevice.h"
 
 namespace orxonox
 {
+    struct KeyboardTraits
+    {
+        typedef Keyboard DeviceClass;
+        typedef OIS::Keyboard OISDeviceClass;
+        typedef KeyEvent ButtonType;
+        typedef KeyEvent& ButtonTypeParam;
+        static const OIS::Type OISDeviceValue = OIS::OISKeyboard;
+    };
+
     /**
     @brief
         Wraps around an OIS::Mouse and forwards the input events to
@@ -62,6 +72,8 @@
         bool keyPressed(const OIS::KeyEvent& arg);
         bool keyReleased(const OIS::KeyEvent& arg);
 
+        static std::string getClassNameImpl() { return "Keyboard"; }
+
         //! Bit mask representing keyboard modifiers
         int modifiers_;
     };

Modified: branches/core4/src/core/input/Mouse.h
===================================================================
--- branches/core4/src/core/input/Mouse.h	2009-07-13 16:03:24 UTC (rev 3284)
+++ branches/core4/src/core/input/Mouse.h	2009-07-13 16:41:58 UTC (rev 3285)
@@ -34,6 +34,15 @@
 
 namespace orxonox
 {
+    struct MouseTraits
+    {
+        typedef Mouse DeviceClass;
+        typedef OIS::Mouse OISDeviceClass;
+        typedef MouseButtonCode::ByEnum ButtonType;
+        typedef MouseButtonCode::ByEnum ButtonTypeParam;
+        static const OIS::Type OISDeviceValue = OIS::OISMouse;
+    };
+
     /**
     @brief
         Wraps around an OIS::Mouse and forwards the input events to
@@ -91,6 +100,8 @@
 
         bool mouseMoved(const OIS::MouseEvent &arg);
 
+        static std::string getClassNameImpl() { return "Mouse"; }
+
         // HACK:
         static Mouse* instancePointer_s;
     };




More information about the Orxonox-commit mailing list