Torque3D Documentation / _generateds / winDirectInput.h

winDirectInput.h

Engine/source/platformWin32/winDirectInput.h

More...

Classes:

Public Defines

define
define
XINPUT_DEADZONE() ( 0.24f * FLOAT(0x7FFF) )

Public Typedefs

DWORD(WINAPI *
FN_XInputGetState )(DWORD dwUserIndex, XINPUT_STATE *pState)
DWORD(WINAPI *
FN_XInputSetState )(DWORD dwUserIndex, XINPUT_VIBRATION *pVibration)

Detailed Description

Public Defines

DIRECTINPUT_VERSION() 0x0800
XINPUT_DEADZONE() ( 0.24f * FLOAT(0x7FFF) )
XINPUT_MAX_CONTROLLERS() 4

Public Typedefs

typedef DWORD(WINAPI * FN_XInputGetState )(DWORD dwUserIndex, XINPUT_STATE *pState)
typedef DWORD(WINAPI * FN_XInputSetState )(DWORD dwUserIndex, XINPUT_VIBRATION *pVibration)
  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 _WINDIRECTINPUT_H_
 25#define _WINDIRECTINPUT_H_
 26
 27#ifndef _PLATFORMWIN32_H_
 28#include "platformWin32/platformWin32.h"
 29#endif
 30#ifndef _PLATFORMINPUT_H_
 31#include "platform/platformInput.h"
 32#endif
 33#ifndef _WINDINPUTDEVICE_H_
 34#include "platformWin32/winDInputDevice.h"
 35#endif
 36
 37#define DIRECTINPUT_VERSION 0x0800
 38#include <dinput.h>
 39#include <xinput.h>
 40
 41// XInput related definitions
 42typedef DWORD (WINAPI* FN_XInputGetState)(DWORD dwUserIndex, XINPUT_STATE* pState);
 43typedef DWORD (WINAPI* FN_XInputSetState)(DWORD dwUserIndex, XINPUT_VIBRATION* pVibration);
 44#define XINPUT_MAX_CONTROLLERS 4  // XInput handles up to 4 controllers 
 45#define XINPUT_DEADZONE  ( 0.24f * FLOAT(0x7FFF) )  // Default to 24% of the +/- 32767 range.   This is a reasonable default value but can be altered if needed.
 46struct XINPUT_CONTROLLER_STATE
 47{
 48    XINPUT_STATE    state;
 49    bool            bConnected;
 50};
 51
 52//------------------------------------------------------------------------------
 53class DInputManager : public InputManager
 54{
 55   private:
 56      typedef SimGroup Parent;
 57
 58      // XInput state
 59      HMODULE                 mXInputLib;
 60      FN_XInputGetState       mfnXInputGetState;
 61      FN_XInputSetState       mfnXInputSetState;
 62      XINPUT_CONTROLLER_STATE mXInputStateOld[XINPUT_MAX_CONTROLLERS];
 63      XINPUT_CONTROLLER_STATE mXInputStateNew[XINPUT_MAX_CONTROLLERS];
 64      U32                     mLastDisconnectTime[XINPUT_MAX_CONTROLLERS];
 65      bool                    mXInputStateReset;
 66      bool                    mXInputDeadZoneOn;
 67
 68      /// Number of milliseconds to skip checking an xinput device if it was
 69      /// disconnected on last check.
 70      const static U32 csmDisconnectedSkipDelay = 250;
 71
 72      HMODULE        mDInputLib;
 73      LPDIRECTINPUT8 mDInputInterface;
 74
 75      static bool smJoystickEnabled;
 76      static bool smXInputEnabled;
 77
 78      bool mJoystickActive;
 79      bool mXInputActive;
 80
 81      void  enumerateDevices();
 82
 83      static BOOL CALLBACK EnumDevicesProc( const DIDEVICEINSTANCE *pddi, LPVOID pvRef );
 84
 85      bool acquire( U8 deviceType, U8 deviceID );
 86      void unacquire( U8 deviceType, U8 deviceID );
 87
 88      // XInput worker functions
 89      void buildXInputEvent( U32 deviceInst, InputEventType objType, InputObjectInstances objInst, InputActionType action, F32 fValue );
 90      void fireXInputConnectEvent( S32 controllerID, bool condition, bool connected );
 91      void fireXInputMoveEvent( S32 controllerID, bool condition, InputObjectInstances objInst, F32 fValue );
 92      void fireXInputButtonEvent( S32 controllerID, bool forceFire, S32 button, InputObjectInstances objInst );
 93      void processXInput();
 94
 95   public:
 96      DInputManager();
 97
 98      bool enable();
 99      void disable();
100
101      void onDeleteNotify( SimObject* object );
102      bool onAdd();
103      void onRemove();
104
105      void process();
106
107      // DirectInput functions:
108      static void init();
109
110      static bool enableJoystick();
111      static void disableJoystick();
112      static bool isJoystickEnabled();
113      bool activateJoystick();
114      void deactivateJoystick();
115      bool isJoystickActive()       { return( mJoystickActive ); }
116
117      static bool enableXInput();
118      static void disableXInput();
119      static bool isXInputEnabled();
120      bool activateXInput();
121      void deactivateXInput();
122      bool isXInputActive()         { return( mXInputActive ); }
123      void resetXInput()            { mXInputStateReset = true; }
124      bool isXInputConnected(S32 controllerID);
125      S32 getXInputState(S32 controllerID, S32 property, bool current);
126
127      // Console interface:
128      const char* getJoystickAxesString( U32 deviceID );
129
130      bool rumble( const char *pDeviceName, F32 x, F32 y );
131};
132
133#endif  // _H_WINDIRECTINPUT_
134