DOOM-3-BFG

DOOM 3 BFG Edition
Log | Files | Refs

win_input.h (3682B)


      1 /*
      2 ===========================================================================
      3 
      4 Doom 3 BFG Edition GPL Source Code
      5 Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. 
      6 
      7 This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").  
      8 
      9 Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
     10 it under the terms of the GNU General Public License as published by
     11 the Free Software Foundation, either version 3 of the License, or
     12 (at your option) any later version.
     13 
     14 Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
     15 but WITHOUT ANY WARRANTY; without even the implied warranty of
     16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     17 GNU General Public License for more details.
     18 
     19 You should have received a copy of the GNU General Public License
     20 along with Doom 3 BFG Edition Source Code.  If not, see <http://www.gnu.org/licenses/>.
     21 
     22 In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code.  If not, please request a copy in writing from id Software at the address below.
     23 
     24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
     25 
     26 ===========================================================================
     27 */
     28 #pragma hdrstop
     29 #include "../../idlib/precompiled.h"
     30 
     31 //#if defined( ID_VS2010 )
     32 //#include "../../../libs/dxsdk_June2010/include/xinput.h"
     33 //#else
     34 #include <Xinput.h>
     35 //#endif
     36 
     37 static const int MAX_JOYSTICKS = 4;
     38 
     39 /*
     40 ================================================================================================
     41 
     42 	Joystick Win32
     43 
     44 ================================================================================================
     45 */
     46 
     47 struct controllerState_t {
     48 	// the current states are updated by the input thread at 250 hz
     49 	XINPUT_STATE	current;
     50 
     51 	// the previous state is latched at polling time
     52 	XINPUT_STATE	previous;
     53 
     54 	// The current button bits are or'd into this at the high sampling rate, then
     55 	// zero'd by the main thread when a usercmd_t is created.  This prevents the
     56 	// complete missing of a button press that went down and up between two usercmd_t
     57 	// creations, although it can add sn extra frame of latency to sensing a release.
     58 	int				buttonBits;
     59 
     60 	// Only valid controllers will have their rumble set
     61 	bool			valid;
     62 };
     63 
     64 
     65 class idJoystickWin32 : idJoystick {
     66 public:
     67 					idJoystickWin32();
     68 
     69 	virtual bool	Init();
     70 	virtual void	SetRumble( int deviceNum, int rumbleLow, int rumbleHigh );
     71 	virtual int		PollInputEvents( int inputDeviceNum );
     72 	virtual int		ReturnInputEvent( const int n, int &action, int &value );
     73 	virtual void	EndInputEvents() {}
     74 
     75 protected:
     76 	friend void		JoystickSamplingThread( void *data );
     77 
     78 	void 			PushButton( int inputDeviceNum, int key, bool value );
     79 	void 			PostInputEvent( int inputDeviceNum, int event, int value, int range = 16384 );
     80 
     81 	idSysMutex				mutexXis;		// lock this before using currentXis or stickIntegrations
     82 	HANDLE					timer;			// fire every 4 msec
     83 
     84 	int						numEvents;
     85 
     86 	struct {
     87 		int event;
     88 		int value;
     89 	}						events[ MAX_JOY_EVENT ];
     90 
     91 	controllerState_t		controllers[ MAX_JOYSTICKS ];
     92 
     93 	// should these be per-controller?
     94 	bool					buttonStates[MAX_INPUT_DEVICES][K_LAST_KEY];	// For keeping track of button up/down events
     95 	int						joyAxis[MAX_INPUT_DEVICES][MAX_JOYSTICK_AXIS];			// For keeping track of joystick axises
     96 };