Torque3D Documentation / _generateds / sdlInputManager.h

sdlInputManager.h

Engine/source/platformSDL/sdlInputManager.h

More...

Classes:

Detailed Description

  1
  2//-----------------------------------------------------------------------------
  3// Copyright (c) 2012 GarageGames, LLC
  4//
  5// Permission is hereby granted, free of charge, to any person obtaining a copy
  6// of this software and associated documentation files (the "Software"), to
  7// deal in the Software without restriction, including without limitation the
  8// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
  9// sell copies of the Software, and to permit persons to whom the Software is
 10// furnished to do so, subject to the following conditions:
 11//
 12// The above copyright notice and this permission notice shall be included in
 13// all copies or substantial portions of the Software.
 14//
 15// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 16// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 17// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 18// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 19// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 20// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 21// IN THE SOFTWARE.
 22//-----------------------------------------------------------------------------
 23
 24#ifndef _SDLINPUTMANAGER_H_
 25#define _SDLINPUTMANAGER_H_
 26
 27#ifndef _PLATFORMINPUT_H_
 28#include "platform/platformInput.h"
 29#endif
 30#include "SDL.h"
 31
 32//------------------------------------------------------------------------------
 33class SDLInputManager : public InputManager
 34{
 35   enum Constants {
 36      MaxJoysticks = 4,          // Up to 4 simultaneous joysticks
 37      MaxControllers = 4,        // Up to 4 simultaneous controllers
 38      MaxHats = 2,               // Maximum 2 hats per device
 39      MaxBalls = 2,              // Maximum 2 trackballs per device
 40      MaxControllerAxes = 7,     // From map_StringForControllerAxis[] in SDL_gamecontroller.c
 41      MaxControllerButtons = 16  // From map_StringForControllerButton[] in SDL_gamecontroller.c
 42   };
 43
 44   struct controllerState
 45   {
 46      S32 sdlInstID;    // SDL device instance id
 47      U32 torqueInstID; // Torque device instance id
 48      SDL_GameController *inputDevice;
 49   };
 50
 51   struct joystickState
 52   {
 53      S32 sdlInstID;    // SDL device instance id
 54      U32 torqueInstID; // Torque device instance id
 55      SDL_Joystick *inputDevice;
 56      U32 numAxes;
 57      U8 lastHatState[MaxHats];
 58
 59      void reset();
 60   };
 61
 62private:
 63   typedef InputManager Parent;
 64
 65   static S32 map_EventForControllerAxis[MaxControllerAxes];
 66   static S32 map_EventForControllerButton[MaxControllerButtons];
 67
 68   static bool smJoystickEnabled;
 69   static bool smJoystickSplitAxesLR;
 70   static bool smControllerEnabled;
 71   static bool smPOVButtonEvents;
 72   static bool smPOVMaskEvents;
 73
 74   joystickState mJoysticks[MaxJoysticks];
 75   controllerState mControllers[MaxControllers];
 76
 77   // Used to look up a torque instance based on a device inst
 78   HashTable<S32, joystickState*> mJoystickMap;
 79   HashTable<S32, controllerState*> mControllerMap;
 80
 81   bool mJoystickActive;
 82
 83   void deviceConnectedCallback(S32 index);
 84   bool closeControllerByIndex(S32 index);
 85   void closeController(SDL_JoystickID sdlId);
 86   bool closeJoystickByIndex(S32 index);
 87   void closeJoystick(SDL_JoystickID sdlId);
 88
 89   void buildInputEvent(U32 deviceType, U32 deviceInst, InputEventType objType, InputObjectInstances objInst, InputActionType action, S32 iValue);
 90   void buildInputEvent(U32 deviceType, U32 deviceInst, InputEventType objType, InputObjectInstances objInst, InputActionType action, F32 fValue);
 91   void buildHatEvents(U32 deviceType, U32 deviceInst, U8 lastState, U8 currentState, S32 hatIndex);
 92
 93public:
 94   DECLARE_STATIC_CLASS(SDLInputManager);
 95
 96public:
 97   SDLInputManager();
 98
 99   bool enable();
100   void disable();
101   void process();
102
103   void processEvent(SDL_Event &evt);
104
105   static void init();
106
107   // Console interface:
108   S32 openJoystick(S32 sdlIndex, S32 requestedTID);
109   S32 openController(S32 sdlIndex, S32 requestedTID);
110   void closeDevice(S32 sdlIndex);
111   S32 getJoystickOpenState(S32 sdlIndex);
112   void getJoystickTorqueInst(S32 sdlIndex, char* instBuffer);
113};
114
115#endif  // _SDLINPUTMANAGER_H_
116