Torque3D Documentation / _generateds / winDInputDevice.h

winDInputDevice.h

Engine/source/platformWin32/winDInputDevice.h

More...

Classes:

Public Defines

define

Public Functions

Detailed Description

Public Defines

DIRECTINPUT_VERSION() 0x0800

Public Functions

DIK_to_Key(U8 dikCode)

Key_to_DIK(U16 keyCode)

  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 _WINDINPUTDEVICE_H_
 25#define _WINDINPUTDEVICE_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
 34#define DIRECTINPUT_VERSION 0x0800
 35#include <dinput.h>
 36
 37
 38class DInputDevice : public InputDevice
 39{
 40   public:
 41      static LPDIRECTINPUT8 smDInputInterface;
 42
 43   protected:
 44      enum Constants
 45      {
 46         QUEUED_BUFFER_SIZE   = 128,
 47
 48         SIZEOF_BUTTON = 1,                  // size of an object's data in bytes
 49         SIZEOF_KEY    = 1,
 50         SIZEOF_AXIS   = 4,
 51         SIZEOF_POV    = 4,
 52      };
 53
 54      static U8   smDeviceCount[ NUM_INPUT_DEVICE_TYPES ];
 55      static bool smInitialized;
 56
 57      /// Are we an XInput device?
 58      bool mIsXInput;
 59
 60      //--------------------------------------
 61      LPDIRECTINPUTDEVICE8 mDevice;
 62      DIDEVICEINSTANCE     mDeviceInstance;
 63      DIDEVCAPS            mDeviceCaps;
 64      U8                   mDeviceType;
 65      U8                   mDeviceID;
 66
 67      bool                 mAcquired;
 68      bool                 mNeedSync;
 69
 70      LPDIRECTINPUTEFFECT  mForceFeedbackEffect;   ///< Holds our DirectInput FF Effect
 71      DWORD                mNumForceFeedbackAxes;  ///< # axes (we only support 0, 1, or 2
 72      DWORD                mForceFeedbackAxes[2];  ///< Force Feedback axes offsets into DIOBJECTFORMAT
 73
 74      //--------------------------------------
 75      DIDEVICEOBJECTINSTANCE* mObjInstance;
 76      DIOBJECTDATAFORMAT*     mObjFormat;
 77      ObjInfo*                mObjInfo;
 78      U8*                     mObjBuffer1;    // polled device input buffers
 79      U8*                     mObjBuffer2;
 80      U8*                     mPrevObjBuffer; // points to buffer 1 or 2
 81
 82      // Hack for POV
 83      S32 mPrevPOVPos;
 84
 85      U32 mObjBufferSize;                     // size of objBuffer*
 86      U32 mObjCount;                          // number of objects on this device
 87      U32 mObjEnumCount;                      // used during enumeration ONLY
 88      U32 mObjBufferOfs;                      // used during enumeration ONLY
 89
 90      static BOOL CALLBACK EnumObjectsProc( const DIDEVICEOBJECTINSTANCE *doi, LPVOID pvRef );
 91
 92      bool enumerateObjects();
 93      bool processAsync();
 94      bool processImmediate();
 95
 96      DWORD findObjInstance( DWORD offset );
 97      bool  buildEvent( DWORD offset, S32 newData, S32 oldData );
 98
 99   public:
100      DInputDevice( const DIDEVICEINSTANCE* deviceInst );
101      ~DInputDevice();
102
103      static void init();
104 
105      bool create();
106      void destroy();
107
108      bool acquire();
109      bool unacquire();
110
111      bool isAcquired();
112      bool isPolled();
113
114      U8 getDeviceType();
115      U8 getDeviceID();
116
117      const char* getName();
118      const char* getProductName();
119
120      // Constant Effect Force Feedback
121      void rumble( F32 x, F32 y );
122
123      // Console interface functions:
124      const char* getJoystickAxesString();
125      static bool joystickDetected();
126      //
127
128      bool process();
129};
130
131//------------------------------------------------------------------------------
132inline bool DInputDevice::isAcquired()
133{
134   return mAcquired;
135}
136
137//------------------------------------------------------------------------------
138inline bool DInputDevice::isPolled()
139{
140   //return true;
141   return ( mDeviceCaps.dwFlags & DIDC_POLLEDDEVICE ) != 0;
142}
143
144//------------------------------------------------------------------------------
145inline U8 DInputDevice::getDeviceType()
146{
147   return mDeviceType;
148}
149
150//------------------------------------------------------------------------------
151inline U8 DInputDevice::getDeviceID()
152{
153   return mDeviceID;
154}
155
156//------------------------------------------------------------------------------
157//------------------------------------------------------------------------------
158InputObjectInstances DIK_to_Key( U8 dikCode );
159U8  Key_to_DIK( U16 keyCode );
160#endif // _H_WINDINPUTDEVICE_
161