Removed DirectInput mouse support. Microsoft does not recommend to use DI for mouse handling anymore.

Removed midi controller/joystick support in platform code.
This commit is contained in:
Artem Kharytoniuk 2016-07-14 22:33:22 +03:00
parent 00bde24f33
commit ce760440ae
4 changed files with 4 additions and 871 deletions

View File

@ -31,70 +31,17 @@ typedef struct {
qboolean mouseActive; qboolean mouseActive;
qboolean mouseInitialized; qboolean mouseInitialized;
qboolean mouseStartupDelayed; // delay mouse init to try DI again when we have a window
} WinMouseVars_t; } WinMouseVars_t;
static WinMouseVars_t s_wmv; static WinMouseVars_t s_wmv;
static int window_center_x, window_center_y; static int window_center_x, window_center_y;
//
// MIDI definitions
//
static void IN_StartupMIDI( void );
static void IN_ShutdownMIDI( void );
#define MAX_MIDIIN_DEVICES 8
typedef struct {
int numDevices;
MIDIINCAPS caps[MAX_MIDIIN_DEVICES];
HMIDIIN hMidiIn;
} MidiInfo_t;
static MidiInfo_t s_midiInfo;
//
// Joystick definitions
//
#define JOY_MAX_AXES 6 // X, Y, Z, R, U, V
typedef struct {
qboolean avail;
int id; // joystick number
JOYCAPS jc;
int oldbuttonstate;
int oldpovstate;
JOYINFOEX ji;
} joystickInfo_t;
static joystickInfo_t joy;
cvar_t *in_midi;
cvar_t *in_midiport;
cvar_t *in_midichannel;
cvar_t *in_mididevice;
cvar_t *in_mouse; cvar_t *in_mouse;
cvar_t *in_logitechbug; cvar_t *in_logitechbug;
cvar_t *in_joystick;
cvar_t *in_joyBallScale;
cvar_t *in_debugJoystick;
cvar_t *joy_threshold;
qboolean in_appactive; qboolean in_appactive;
// forward-referenced functions
void IN_StartupJoystick (void);
void IN_JoyMove(void);
static void MidiInfo_f( void );
/* /*
============================================================ ============================================================
@ -183,309 +130,6 @@ void IN_Win32Mouse( int *mx, int *my ) {
*my = current_pos.y - window_center_y; *my = current_pos.y - window_center_y;
} }
/*
============================================================
DIRECT INPUT MOUSE CONTROL
============================================================
*/
#undef DEFINE_GUID
#define DEFINE_GUID(name, l, w1, w2, b1, b2, b3, b4, b5, b6, b7, b8) \
EXTERN_C const GUID name \
= { l, w1, w2, { b1, b2, b3, b4, b5, b6, b7, b8 } }
DEFINE_GUID(GUID_SysMouse, 0x6F1D2B60,0xD5A0,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
DEFINE_GUID(GUID_XAxis, 0xA36D02E0,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
DEFINE_GUID(GUID_YAxis, 0xA36D02E1,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
DEFINE_GUID(GUID_ZAxis, 0xA36D02E2,0xC9F3,0x11CF,0xBF,0xC7,0x44,0x45,0x53,0x54,0x00,0x00);
#define DINPUT_BUFFERSIZE 16
#define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion,
LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter);
static HINSTANCE hInstDI;
typedef struct MYDATA {
LONG lX; // X axis goes here
LONG lY; // Y axis goes here
LONG lZ; // Z axis goes here
BYTE bButtonA; // One button goes here
BYTE bButtonB; // Another button goes here
BYTE bButtonC; // Another button goes here
BYTE bButtonD; // Another button goes here
} MYDATA;
static DIOBJECTDATAFORMAT rgodf[] = {
{ &GUID_XAxis, FIELD_OFFSET(MYDATA, lX), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
{ &GUID_YAxis, FIELD_OFFSET(MYDATA, lY), DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
{ &GUID_ZAxis, FIELD_OFFSET(MYDATA, lZ), 0x80000000 | DIDFT_AXIS | DIDFT_ANYINSTANCE, 0,},
{ 0, FIELD_OFFSET(MYDATA, bButtonA), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
{ 0, FIELD_OFFSET(MYDATA, bButtonB), DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
{ 0, FIELD_OFFSET(MYDATA, bButtonC), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
{ 0, FIELD_OFFSET(MYDATA, bButtonD), 0x80000000 | DIDFT_BUTTON | DIDFT_ANYINSTANCE, 0,},
};
#define NUM_OBJECTS (sizeof(rgodf) / sizeof(rgodf[0]))
// NOTE TTimo: would be easier using c_dfDIMouse or c_dfDIMouse2
static DIDATAFORMAT df = {
sizeof(DIDATAFORMAT), // this structure
sizeof(DIOBJECTDATAFORMAT), // size of object data format
DIDF_RELAXIS, // absolute axis coordinates
sizeof(MYDATA), // device data size
NUM_OBJECTS, // number of objects
rgodf, // and here they are
};
static LPDIRECTINPUT g_pdi;
static LPDIRECTINPUTDEVICE g_pMouse;
void IN_DIMouse( int *mx, int *my );
/*
========================
IN_InitDIMouse
========================
*/
qboolean IN_InitDIMouse( void ) {
HRESULT hr;
int x, y;
DIPROPDWORD dipdw = {
{
sizeof(DIPROPDWORD), // diph.dwSize
sizeof(DIPROPHEADER), // diph.dwHeaderSize
0, // diph.dwObj
DIPH_DEVICE, // diph.dwHow
},
DINPUT_BUFFERSIZE, // dwData
};
Com_Printf( "Initializing DirectInput...\n");
if (!hInstDI) {
hInstDI = LoadLibrary("dinput.dll");
if (hInstDI == NULL) {
Com_Printf ("Couldn't load dinput.dll\n");
return qfalse;
}
}
if (!pDirectInputCreate) {
pDirectInputCreate = (HRESULT (__stdcall *)(HINSTANCE,DWORD ,struct IDirectInputA ** ,struct IUnknown *))
GetProcAddress(hInstDI,"DirectInputCreateA");
if (!pDirectInputCreate) {
Com_Printf ("Couldn't get DI proc addr\n");
return qfalse;
}
}
// register with DirectInput and get an IDirectInput to play with.
hr = iDirectInputCreate( g_wv.hInstance, DIRECTINPUT_VERSION, &g_pdi, NULL);
if (FAILED(hr)) {
Com_Printf ("iDirectInputCreate failed\n");
return qfalse;
}
// obtain an interface to the system mouse device.
hr = IDirectInput_CreateDevice(g_pdi, GUID_SysMouse, &g_pMouse, NULL);
if (FAILED(hr)) {
Com_Printf ("Couldn't open DI mouse device\n");
return qfalse;
}
// set the data format to "mouse format".
hr = IDirectInputDevice_SetDataFormat(g_pMouse, &df);
if (FAILED(hr)) {
Com_Printf ("Couldn't set DI mouse format\n");
return qfalse;
}
// set the cooperativity level.
hr = IDirectInputDevice_SetCooperativeLevel(g_pMouse, g_wv.hWnd,
DISCL_EXCLUSIVE | DISCL_FOREGROUND);
// https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=50
if (FAILED(hr)) {
Com_Printf ("Couldn't set DI coop level\n");
return qfalse;
}
// set the buffer size to DINPUT_BUFFERSIZE elements.
// the buffer size is a DWORD property associated with the device
hr = IDirectInputDevice_SetProperty(g_pMouse, DIPROP_BUFFERSIZE, &dipdw.diph);
if (FAILED(hr)) {
Com_Printf ("Couldn't set DI buffersize\n");
return qfalse;
}
// clear any pending samples
IN_DIMouse( &x, &y );
IN_DIMouse( &x, &y );
Com_Printf( "DirectInput initialized.\n");
return qtrue;
}
/*
==========================
IN_ShutdownDIMouse
==========================
*/
void IN_ShutdownDIMouse( void ) {
if (g_pMouse) {
IDirectInputDevice_Release(g_pMouse);
g_pMouse = NULL;
}
if (g_pdi) {
IDirectInput_Release(g_pdi);
g_pdi = NULL;
}
}
/*
==========================
IN_ActivateDIMouse
==========================
*/
void IN_ActivateDIMouse( void ) {
HRESULT hr;
if (!g_pMouse) {
return;
}
// we may fail to reacquire if the window has been recreated
hr = IDirectInputDevice_Acquire( g_pMouse );
if (FAILED(hr)) {
if ( !IN_InitDIMouse() ) {
Com_Printf ("Falling back to Win32 mouse support...\n");
Cvar_Set( "in_mouse", "-1" );
}
}
}
/*
==========================
IN_DeactivateDIMouse
==========================
*/
void IN_DeactivateDIMouse( void ) {
if (!g_pMouse) {
return;
}
IDirectInputDevice_Unacquire( g_pMouse );
}
/*
===================
IN_DIMouse
===================
*/
void IN_DIMouse( int *mx, int *my ) {
DIDEVICEOBJECTDATA od;
DIMOUSESTATE state;
DWORD dwElements;
HRESULT hr;
int value;
static float oldSysTime;
if ( !g_pMouse ) {
return;
}
// fetch new events
for (;;)
{
dwElements = 1;
hr = IDirectInputDevice_GetDeviceData(g_pMouse,
sizeof(DIDEVICEOBJECTDATA), &od, &dwElements, 0);
if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED)) {
IDirectInputDevice_Acquire(g_pMouse);
return;
}
/* Unable to read data or no data available */
if ( FAILED(hr) ) {
break;
}
if ( dwElements == 0 ) {
break;
}
switch (od.dwOfs) {
case DIMOFS_BUTTON0:
if (od.dwData & 0x80)
Sys_QueEvent( od.dwTimeStamp, SE_KEY, K_MOUSE1, qtrue, 0, NULL );
else
Sys_QueEvent( od.dwTimeStamp, SE_KEY, K_MOUSE1, qfalse, 0, NULL );
break;
case DIMOFS_BUTTON1:
if (od.dwData & 0x80)
Sys_QueEvent( od.dwTimeStamp, SE_KEY, K_MOUSE2, qtrue, 0, NULL );
else
Sys_QueEvent( od.dwTimeStamp, SE_KEY, K_MOUSE2, qfalse, 0, NULL );
break;
case DIMOFS_BUTTON2:
if (od.dwData & 0x80)
Sys_QueEvent( od.dwTimeStamp, SE_KEY, K_MOUSE3, qtrue, 0, NULL );
else
Sys_QueEvent( od.dwTimeStamp, SE_KEY, K_MOUSE3, qfalse, 0, NULL );
break;
case DIMOFS_BUTTON3:
if (od.dwData & 0x80)
Sys_QueEvent( od.dwTimeStamp, SE_KEY, K_MOUSE4, qtrue, 0, NULL );
else
Sys_QueEvent( od.dwTimeStamp, SE_KEY, K_MOUSE4, qfalse, 0, NULL );
break;
// https://zerowing.idsoftware.com/bugzilla/show_bug.cgi?id=50
case DIMOFS_Z:
value = od.dwData;
if (value == 0) {
} else if (value < 0) {
Sys_QueEvent( od.dwTimeStamp, SE_KEY, K_MWHEELDOWN, qtrue, 0, NULL );
Sys_QueEvent( od.dwTimeStamp, SE_KEY, K_MWHEELDOWN, qfalse, 0, NULL );
} else {
Sys_QueEvent( od.dwTimeStamp, SE_KEY, K_MWHEELUP, qtrue, 0, NULL );
Sys_QueEvent( od.dwTimeStamp, SE_KEY, K_MWHEELUP, qfalse, 0, NULL );
}
break;
}
}
// read the raw delta counter and ignore
// the individual sample time / values
hr = IDirectInputDevice_GetDeviceState(g_pMouse,
sizeof(DIDEVICEOBJECTDATA), &state);
if ( FAILED(hr) ) {
*mx = *my = 0;
return;
}
*mx = state.lX;
*my = state.lY;
}
/* /*
============================================================ ============================================================
@ -518,9 +162,6 @@ void IN_ActivateMouse( void )
s_wmv.mouseActive = qtrue; s_wmv.mouseActive = qtrue;
if ( in_mouse->integer != -1 ) {
IN_ActivateDIMouse();
}
IN_ActivateWin32Mouse(); IN_ActivateWin32Mouse();
} }
@ -541,7 +182,6 @@ void IN_DeactivateMouse( void ) {
} }
s_wmv.mouseActive = qfalse; s_wmv.mouseActive = qfalse;
IN_DeactivateDIMouse();
IN_DeactivateWin32Mouse(); IN_DeactivateWin32Mouse();
} }
@ -555,38 +195,15 @@ IN_StartupMouse
void IN_StartupMouse( void ) void IN_StartupMouse( void )
{ {
s_wmv.mouseInitialized = qfalse; s_wmv.mouseInitialized = qfalse;
s_wmv.mouseStartupDelayed = qfalse;
if ( in_mouse->integer == 0 ) { if ( in_mouse->integer == 0 ) {
Com_Printf ("Mouse control not active.\n"); Com_Printf ("Mouse control not active.\n");
return; return;
} }
// nt4.0 direct input is screwed up
if ( ( g_wv.osversion.dwPlatformId == VER_PLATFORM_WIN32_NT ) &&
( g_wv.osversion.dwMajorVersion == 4 ) )
{
Com_Printf ("Disallowing DirectInput on NT 4.0\n");
Cvar_Set( "in_mouse", "-1" );
}
if ( in_mouse->integer == -1 ) {
Com_Printf ("Skipping check for DirectInput\n");
} else {
if (!g_wv.hWnd)
{
Com_Printf ("No window for DirectInput mouse init, delaying\n");
s_wmv.mouseStartupDelayed = qtrue;
return;
}
if ( IN_InitDIMouse() ) {
s_wmv.mouseInitialized = qtrue;
return;
}
Com_Printf ("Falling back to Win32 mouse support...\n");
}
s_wmv.mouseInitialized = qtrue; s_wmv.mouseInitialized = qtrue;
IN_InitWin32Mouse(); IN_InitWin32Mouse();
Com_Printf ("Win32 mouse input initialized.\n");
} }
/* /*
@ -629,11 +246,7 @@ IN_MouseMove
void IN_MouseMove ( void ) { void IN_MouseMove ( void ) {
int mx, my; int mx, my;
if ( g_pMouse ) {
IN_DIMouse( &mx, &my );
} else {
IN_Win32Mouse( &mx, &my ); IN_Win32Mouse( &mx, &my );
}
if ( !mx && !my ) { if ( !mx && !my ) {
return; return;
@ -657,12 +270,9 @@ IN_Startup
void IN_Startup( void ) { void IN_Startup( void ) {
Com_Printf ("\n------- Input Initialization -------\n"); Com_Printf ("\n------- Input Initialization -------\n");
IN_StartupMouse (); IN_StartupMouse ();
IN_StartupJoystick ();
IN_StartupMIDI();
Com_Printf ("------------------------------------\n"); Com_Printf ("------------------------------------\n");
in_mouse->modified = qfalse; in_mouse->modified = qfalse;
in_joystick->modified = qfalse;
} }
/* /*
@ -672,9 +282,6 @@ IN_Shutdown
*/ */
void IN_Shutdown( void ) { void IN_Shutdown( void ) {
IN_DeactivateMouse(); IN_DeactivateMouse();
IN_ShutdownDIMouse();
IN_ShutdownMIDI();
Cmd_RemoveCommand("midiinfo" );
} }
@ -684,25 +291,9 @@ IN_Init
=========== ===========
*/ */
void IN_Init( void ) { void IN_Init( void ) {
// MIDI input controler variables
in_midi = Cvar_Get ("in_midi", "0", CVAR_ARCHIVE);
in_midiport = Cvar_Get ("in_midiport", "1", CVAR_ARCHIVE);
in_midichannel = Cvar_Get ("in_midichannel", "1", CVAR_ARCHIVE);
in_mididevice = Cvar_Get ("in_mididevice", "0", CVAR_ARCHIVE);
Cmd_AddCommand( "midiinfo", MidiInfo_f );
// mouse variables
in_mouse = Cvar_Get ("in_mouse", "1", CVAR_ARCHIVE|CVAR_LATCH); in_mouse = Cvar_Get ("in_mouse", "1", CVAR_ARCHIVE|CVAR_LATCH);
in_logitechbug = Cvar_Get ("in_logitechbug", "0", CVAR_ARCHIVE); in_logitechbug = Cvar_Get ("in_logitechbug", "0", CVAR_ARCHIVE);
// joystick variables
in_joystick = Cvar_Get ("in_joystick", "0", CVAR_ARCHIVE|CVAR_LATCH);
in_joyBallScale = Cvar_Get ("in_joyBallScale", "0.02", CVAR_ARCHIVE);
in_debugJoystick = Cvar_Get ("in_debugjoystick", "0", CVAR_TEMP);
joy_threshold = Cvar_Get ("joy_threshold", "0.15", CVAR_ARCHIVE);
IN_Startup(); IN_Startup();
} }
@ -734,16 +325,7 @@ Called every frame, even if not generating commands
================== ==================
*/ */
void IN_Frame (void) { void IN_Frame (void) {
// post joystick events
IN_JoyMove();
if ( !s_wmv.mouseInitialized ) { if ( !s_wmv.mouseInitialized ) {
if (s_wmv.mouseStartupDelayed && g_wv.hWnd)
{
Com_Printf("Proceeding with delayed mouse init\n");
IN_StartupMouse();
s_wmv.mouseStartupDelayed = qfalse;
}
return; return;
} }
@ -768,381 +350,3 @@ void IN_Frame (void) {
IN_MouseMove(); IN_MouseMove();
} }
/*
===================
IN_ClearStates
===================
*/
void IN_ClearStates (void)
{
s_wmv.oldButtonState = 0;
}
/*
=========================================================================
JOYSTICK
=========================================================================
*/
/*
===============
IN_StartupJoystick
===============
*/
void IN_StartupJoystick (void) {
int numdevs;
MMRESULT mmr;
// assume no joystick
joy.avail = qfalse;
if (! in_joystick->integer ) {
Com_Printf ("Joystick is not active.\n");
return;
}
// verify joystick driver is present
if ((numdevs = joyGetNumDevs ()) == 0)
{
Com_Printf ("joystick not found -- driver not present\n");
return;
}
// cycle through the joystick ids for the first valid one
mmr = 0;
for (joy.id=0 ; joy.id<numdevs ; joy.id++)
{
Com_Memset (&joy.ji, 0, sizeof(joy.ji));
joy.ji.dwSize = sizeof(joy.ji);
joy.ji.dwFlags = JOY_RETURNCENTERED;
if ((mmr = joyGetPosEx (joy.id, &joy.ji)) == JOYERR_NOERROR)
break;
}
// abort startup if we didn't find a valid joystick
if (mmr != JOYERR_NOERROR)
{
Com_Printf ("joystick not found -- no valid joysticks (%x)\n", mmr);
return;
}
// get the capabilities of the selected joystick
// abort startup if command fails
Com_Memset (&joy.jc, 0, sizeof(joy.jc));
if ((mmr = joyGetDevCaps (joy.id, &joy.jc, sizeof(joy.jc))) != JOYERR_NOERROR)
{
Com_Printf ("joystick not found -- invalid joystick capabilities (%x)\n", mmr);
return;
}
Com_Printf( "Joystick found.\n" );
Com_Printf( "Pname: %s\n", joy.jc.szPname );
Com_Printf( "OemVxD: %s\n", joy.jc.szOEMVxD );
Com_Printf( "RegKey: %s\n", joy.jc.szRegKey );
Com_Printf( "Numbuttons: %i / %i\n", joy.jc.wNumButtons, joy.jc.wMaxButtons );
Com_Printf( "Axis: %i / %i\n", joy.jc.wNumAxes, joy.jc.wMaxAxes );
Com_Printf( "Caps: 0x%x\n", joy.jc.wCaps );
if ( joy.jc.wCaps & JOYCAPS_HASPOV ) {
Com_Printf( "HASPOV\n" );
} else {
Com_Printf( "no POV\n" );
}
// old button and POV states default to no buttons pressed
joy.oldbuttonstate = 0;
joy.oldpovstate = 0;
// mark the joystick as available
joy.avail = qtrue;
}
/*
===========
JoyToF
===========
*/
float JoyToF( int value ) {
float fValue;
// move centerpoint to zero
value -= 32768;
// convert range from -32768..32767 to -1..1
fValue = (float)value / 32768.0;
if ( fValue < -1 ) {
fValue = -1;
}
if ( fValue > 1 ) {
fValue = 1;
}
return fValue;
}
int JoyToI( int value ) {
// move centerpoint to zero
value -= 32768;
return value;
}
int joyDirectionKeys[16] = {
K_LEFTARROW, K_RIGHTARROW,
K_UPARROW, K_DOWNARROW,
K_JOY16, K_JOY17,
K_JOY18, K_JOY19,
K_JOY20, K_JOY21,
K_JOY22, K_JOY23,
K_JOY24, K_JOY25,
K_JOY26, K_JOY27
};
/*
===========
IN_JoyMove
===========
*/
void IN_JoyMove( void ) {
float fAxisValue;
int i;
DWORD buttonstate, povstate;
int x, y;
// verify joystick is available and that the user wants to use it
if ( !joy.avail ) {
return;
}
// collect the joystick data, if possible
Com_Memset (&joy.ji, 0, sizeof(joy.ji));
joy.ji.dwSize = sizeof(joy.ji);
joy.ji.dwFlags = JOY_RETURNALL;
if ( joyGetPosEx (joy.id, &joy.ji) != JOYERR_NOERROR ) {
// read error occurred
// turning off the joystick seems too harsh for 1 read error,\
// but what should be done?
// Com_Printf ("IN_ReadJoystick: no response\n");
// joy.avail = false;
return;
}
if ( in_debugJoystick->integer ) {
Com_Printf( "%8x %5i %5.2f %5.2f %5.2f %5.2f %6i %6i\n",
joy.ji.dwButtons,
joy.ji.dwPOV,
JoyToF( joy.ji.dwXpos ), JoyToF( joy.ji.dwYpos ),
JoyToF( joy.ji.dwZpos ), JoyToF( joy.ji.dwRpos ),
JoyToI( joy.ji.dwUpos ), JoyToI( joy.ji.dwVpos ) );
}
// loop through the joystick buttons
// key a joystick event or auxillary event for higher number buttons for each state change
buttonstate = joy.ji.dwButtons;
for ( i=0 ; i < joy.jc.wNumButtons ; i++ ) {
if ( (buttonstate & (1<<i)) && !(joy.oldbuttonstate & (1<<i)) ) {
Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, K_JOY1 + i, qtrue, 0, NULL );
}
if ( !(buttonstate & (1<<i)) && (joy.oldbuttonstate & (1<<i)) ) {
Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, K_JOY1 + i, qfalse, 0, NULL );
}
}
joy.oldbuttonstate = buttonstate;
povstate = 0;
// convert main joystick motion into 6 direction button bits
for (i = 0; i < joy.jc.wNumAxes && i < 4 ; i++) {
// get the floating point zero-centered, potentially-inverted data for the current axis
fAxisValue = JoyToF( (&joy.ji.dwXpos)[i] );
if ( fAxisValue < -joy_threshold->value ) {
povstate |= (1<<(i*2));
} else if ( fAxisValue > joy_threshold->value ) {
povstate |= (1<<(i*2+1));
}
}
// convert POV information from a direction into 4 button bits
if ( joy.jc.wCaps & JOYCAPS_HASPOV ) {
if ( joy.ji.dwPOV != JOY_POVCENTERED ) {
if (joy.ji.dwPOV == JOY_POVFORWARD)
povstate |= 1<<12;
if (joy.ji.dwPOV == JOY_POVBACKWARD)
povstate |= 1<<13;
if (joy.ji.dwPOV == JOY_POVRIGHT)
povstate |= 1<<14;
if (joy.ji.dwPOV == JOY_POVLEFT)
povstate |= 1<<15;
}
}
// determine which bits have changed and key an auxillary event for each change
for (i=0 ; i < 16 ; i++) {
if ( (povstate & (1<<i)) && !(joy.oldpovstate & (1<<i)) ) {
Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, joyDirectionKeys[i], qtrue, 0, NULL );
}
if ( !(povstate & (1<<i)) && (joy.oldpovstate & (1<<i)) ) {
Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, joyDirectionKeys[i], qfalse, 0, NULL );
}
}
joy.oldpovstate = povstate;
// if there is a trackball like interface, simulate mouse moves
if ( joy.jc.wNumAxes >= 6 ) {
x = JoyToI( joy.ji.dwUpos ) * in_joyBallScale->value;
y = JoyToI( joy.ji.dwVpos ) * in_joyBallScale->value;
if ( x || y ) {
Sys_QueEvent( g_wv.sysMsgTime, SE_MOUSE, x, y, 0, NULL );
}
}
}
/*
=========================================================================
MIDI
=========================================================================
*/
static void MIDI_NoteOff( int note )
{
int qkey;
qkey = note - 60 + K_AUX1;
if ( qkey > 255 || qkey < K_AUX1 )
return;
Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, qkey, qfalse, 0, NULL );
}
static void MIDI_NoteOn( int note, int velocity )
{
int qkey;
if ( velocity == 0 )
MIDI_NoteOff( note );
qkey = note - 60 + K_AUX1;
if ( qkey > 255 || qkey < K_AUX1 )
return;
Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, qkey, qtrue, 0, NULL );
}
static void CALLBACK MidiInProc( HMIDIIN hMidiIn, UINT uMsg, DWORD dwInstance,
DWORD dwParam1, DWORD dwParam2 )
{
int message;
switch ( uMsg )
{
case MIM_OPEN:
break;
case MIM_CLOSE:
break;
case MIM_DATA:
message = dwParam1 & 0xff;
// note on
if ( ( message & 0xf0 ) == 0x90 )
{
if ( ( ( message & 0x0f ) + 1 ) == in_midichannel->integer )
MIDI_NoteOn( ( dwParam1 & 0xff00 ) >> 8, ( dwParam1 & 0xff0000 ) >> 16 );
}
else if ( ( message & 0xf0 ) == 0x80 )
{
if ( ( ( message & 0x0f ) + 1 ) == in_midichannel->integer )
MIDI_NoteOff( ( dwParam1 & 0xff00 ) >> 8 );
}
break;
case MIM_LONGDATA:
break;
case MIM_ERROR:
break;
case MIM_LONGERROR:
break;
}
// Sys_QueEvent( sys_msg_time, SE_KEY, wMsg, qtrue, 0, NULL );
}
static void MidiInfo_f( void )
{
int i;
const char *enableStrings[] = { "disabled", "enabled" };
Com_Printf( "\nMIDI control: %s\n", enableStrings[in_midi->integer != 0] );
Com_Printf( "port: %d\n", in_midiport->integer );
Com_Printf( "channel: %d\n", in_midichannel->integer );
Com_Printf( "current device: %d\n", in_mididevice->integer );
Com_Printf( "number of devices: %d\n", s_midiInfo.numDevices );
for ( i = 0; i < s_midiInfo.numDevices; i++ )
{
if ( i == Cvar_VariableValue( "in_mididevice" ) )
Com_Printf( "***" );
else
Com_Printf( "..." );
Com_Printf( "device %2d: %s\n", i, s_midiInfo.caps[i].szPname );
Com_Printf( "...manufacturer ID: 0x%hx\n", s_midiInfo.caps[i].wMid );
Com_Printf( "...product ID: 0x%hx\n", s_midiInfo.caps[i].wPid );
Com_Printf( "\n" );
}
}
static void IN_StartupMIDI( void )
{
int i;
if ( !Cvar_VariableValue( "in_midi" ) )
return;
//
// enumerate MIDI IN devices
//
s_midiInfo.numDevices = midiInGetNumDevs();
for ( i = 0; i < s_midiInfo.numDevices; i++ )
{
midiInGetDevCaps( i, &s_midiInfo.caps[i], sizeof( s_midiInfo.caps[i] ) );
}
//
// open the MIDI IN port
//
if ( midiInOpen( &s_midiInfo.hMidiIn,
in_mididevice->integer,
( DWORD_PTR ) MidiInProc,
( DWORD_PTR ) NULL,
CALLBACK_FUNCTION ) != MMSYSERR_NOERROR )
{
Com_Printf( "WARNING: could not open MIDI device %d: '%s'\n", in_mididevice->integer , s_midiInfo.caps[( int ) in_mididevice->value] );
return;
}
midiInStart( s_midiInfo.hMidiIn );
}
static void IN_ShutdownMIDI( void )
{
if ( s_midiInfo.hMidiIn )
{
midiInClose( s_midiInfo.hMidiIn );
}
Com_Memset( &s_midiInfo, 0, sizeof( s_midiInfo ) );
}

View File

@ -31,9 +31,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#endif #endif
#define DIRECTSOUND_VERSION 0x0300 #define DIRECTSOUND_VERSION 0x0300
#define DIRECTINPUT_VERSION 0x0300
#include <dinput.h>
#include <dsound.h> #include <dsound.h>
#include <winsock.h> #include <winsock.h>
#include <wsipx.h> #include <wsipx.h>
@ -53,12 +51,6 @@ qboolean Sys_GetPacket ( netadr_t *net_from, msg_t *net_message );
void IN_Init (void); void IN_Init (void);
void IN_Shutdown (void); void IN_Shutdown (void);
void IN_JoystickCommands (void);
void IN_Move (usercmd_t *cmd);
// add additional non keyboard / non mouse movement on top of the keyboard move cmd
void IN_DeactivateWin32Mouse( void);
void IN_Activate (qboolean active); void IN_Activate (qboolean active);
void IN_Frame (void); void IN_Frame (void);

View File

@ -29,8 +29,6 @@ WinVars_t g_wv;
#define WM_MOUSEWHEEL (WM_MOUSELAST+1) // message that will be supported by the OS #define WM_MOUSEWHEEL (WM_MOUSELAST+1) // message that will be supported by the OS
#endif #endif
static UINT MSH_MOUSEWHEEL;
// Console variables that we need to access from this module // Console variables that we need to access from this module
cvar_t *vid_xpos; // X coordinate of window position cvar_t *vid_xpos; // X coordinate of window position
cvar_t *vid_ypos; // Y coordinate of window position cvar_t *vid_ypos; // Y coordinate of window position
@ -232,37 +230,13 @@ LONG WINAPI MainWndProc (
static qboolean flip = qtrue; static qboolean flip = qtrue;
int zDelta, i; int zDelta, i;
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/mouseinput/aboutmouseinput.asp
// Windows 95, Windows NT 3.51 - uses MSH_MOUSEWHEEL
// only relevant for non-DI input
//
// NOTE: not sure how reliable this is anymore, might trigger double wheel events
if (in_mouse->integer != 1)
{
if ( uMsg == MSH_MOUSEWHEEL )
{
if ( ( ( int ) wParam ) > 0 )
{
Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MWHEELUP, qtrue, 0, NULL );
Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MWHEELUP, qfalse, 0, NULL );
}
else
{
Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MWHEELDOWN, qtrue, 0, NULL );
Sys_QueEvent( g_wv.sysMsgTime, SE_KEY, K_MWHEELDOWN, qfalse, 0, NULL );
}
return DefWindowProc (hWnd, uMsg, wParam, lParam);
}
}
switch (uMsg) switch (uMsg)
{ {
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/userinput/mouseinput/aboutmouseinput.asp
// Windows 98/Me, Windows NT 4.0 and later - uses WM_MOUSEWHEEL // Windows 98/Me, Windows NT 4.0 and later - uses WM_MOUSEWHEEL
// only relevant for non-DI input and when console is toggled in window mode // only relevant for non-DI input and when console is toggled in window mode
// if console is toggled in window mode (KEYCATCH_CONSOLE) then mouse is released and DI doesn't see any mouse wheel // if console is toggled in window mode (KEYCATCH_CONSOLE) then mouse is released and DI doesn't see any mouse wheel
if (in_mouse->integer != 1 || (!r_fullscreen->integer && (cls.keyCatchers & KEYCATCH_CONSOLE))) if (!r_fullscreen->integer && (cls.keyCatchers & KEYCATCH_CONSOLE))
{ {
// 120 increments, might be 240 and multiples if wheel goes too fast // 120 increments, might be 240 and multiples if wheel goes too fast
// NOTE Logitech: logitech drivers are screwed and send the message twice? // NOTE Logitech: logitech drivers are screwed and send the message twice?
@ -313,7 +287,6 @@ LONG WINAPI MainWndProc (
vid_ypos = Cvar_Get ("vid_ypos", "22", CVAR_ARCHIVE); vid_ypos = Cvar_Get ("vid_ypos", "22", CVAR_ARCHIVE);
r_fullscreen = Cvar_Get ("r_fullscreen", "1", CVAR_ARCHIVE | CVAR_LATCH ); r_fullscreen = Cvar_Get ("r_fullscreen", "1", CVAR_ARCHIVE | CVAR_LATCH );
MSH_MOUSEWHEEL = RegisterWindowMessage("MSWHEEL_ROLLMSG");
if ( r_fullscreen->integer ) if ( r_fullscreen->integer )
{ {
WIN_DisableAltTab(); WIN_DisableAltTab();

View File

@ -118,8 +118,6 @@ typedef struct
#define ID_ALWAYSRUN 36 #define ID_ALWAYSRUN 36
#define ID_AUTOSWITCH 37 #define ID_AUTOSWITCH 37
#define ID_MOUSESPEED 38 #define ID_MOUSESPEED 38
#define ID_JOYENABLE 39
#define ID_JOYTHRESHOLD 40
#define ID_SMOOTHMOUSE 41 #define ID_SMOOTHMOUSE 41
#define ANIM_IDLE 0 #define ANIM_IDLE 0
@ -205,8 +203,6 @@ typedef struct
menuaction_s chat2; menuaction_s chat2;
menuaction_s chat3; menuaction_s chat3;
menuaction_s chat4; menuaction_s chat4;
menuradiobutton_s joyenable;
menuslider_s joythreshold;
int section; int section;
qboolean waitingforkey; qboolean waitingforkey;
char playerModel[64]; char playerModel[64];
@ -270,8 +266,6 @@ static configcvar_t g_configcvars[] =
{"m_pitch", 0, 0}, {"m_pitch", 0, 0},
{"cg_autoswitch", 0, 0}, {"cg_autoswitch", 0, 0},
{"sensitivity", 0, 0}, {"sensitivity", 0, 0},
{"in_joystick", 0, 0},
{"joy_threshold", 0, 0},
{"m_filter", 0, 0}, {"m_filter", 0, 0},
{"cl_freelook", 0, 0}, {"cl_freelook", 0, 0},
{NULL, 0, 0} {NULL, 0, 0}
@ -320,8 +314,6 @@ static menucommon_s *g_looking_controls[] = {
(menucommon_s *)&s_controls.freelook, (menucommon_s *)&s_controls.freelook,
(menucommon_s *)&s_controls.centerview, (menucommon_s *)&s_controls.centerview,
(menucommon_s *)&s_controls.zoomview, (menucommon_s *)&s_controls.zoomview,
(menucommon_s *)&s_controls.joyenable,
(menucommon_s *)&s_controls.joythreshold,
NULL, NULL,
}; };
@ -811,8 +803,6 @@ static void Controls_GetConfig( void )
s_controls.alwaysrun.curvalue = UI_ClampCvar( 0, 1, Controls_GetCvarValue( "cl_run" ) ); s_controls.alwaysrun.curvalue = UI_ClampCvar( 0, 1, Controls_GetCvarValue( "cl_run" ) );
s_controls.autoswitch.curvalue = UI_ClampCvar( 0, 1, Controls_GetCvarValue( "cg_autoswitch" ) ); s_controls.autoswitch.curvalue = UI_ClampCvar( 0, 1, Controls_GetCvarValue( "cg_autoswitch" ) );
s_controls.sensitivity.curvalue = UI_ClampCvar( 2, 30, Controls_GetCvarValue( "sensitivity" ) ); s_controls.sensitivity.curvalue = UI_ClampCvar( 2, 30, Controls_GetCvarValue( "sensitivity" ) );
s_controls.joyenable.curvalue = UI_ClampCvar( 0, 1, Controls_GetCvarValue( "in_joystick" ) );
s_controls.joythreshold.curvalue = UI_ClampCvar( 0.05f, 0.75f, Controls_GetCvarValue( "joy_threshold" ) );
s_controls.freelook.curvalue = UI_ClampCvar( 0, 1, Controls_GetCvarValue( "cl_freelook" ) ); s_controls.freelook.curvalue = UI_ClampCvar( 0, 1, Controls_GetCvarValue( "cl_freelook" ) );
} }
@ -853,8 +843,6 @@ static void Controls_SetConfig( void )
trap_Cvar_SetValue( "cl_run", s_controls.alwaysrun.curvalue ); trap_Cvar_SetValue( "cl_run", s_controls.alwaysrun.curvalue );
trap_Cvar_SetValue( "cg_autoswitch", s_controls.autoswitch.curvalue ); trap_Cvar_SetValue( "cg_autoswitch", s_controls.autoswitch.curvalue );
trap_Cvar_SetValue( "sensitivity", s_controls.sensitivity.curvalue ); trap_Cvar_SetValue( "sensitivity", s_controls.sensitivity.curvalue );
trap_Cvar_SetValue( "in_joystick", s_controls.joyenable.curvalue );
trap_Cvar_SetValue( "joy_threshold", s_controls.joythreshold.curvalue );
trap_Cvar_SetValue( "cl_freelook", s_controls.freelook.curvalue ); trap_Cvar_SetValue( "cl_freelook", s_controls.freelook.curvalue );
trap_Cmd_ExecuteText( EXEC_APPEND, "in_restart\n" ); trap_Cmd_ExecuteText( EXEC_APPEND, "in_restart\n" );
} }
@ -887,8 +875,6 @@ static void Controls_SetDefaults( void )
s_controls.alwaysrun.curvalue = Controls_GetCvarDefault( "cl_run" ); s_controls.alwaysrun.curvalue = Controls_GetCvarDefault( "cl_run" );
s_controls.autoswitch.curvalue = Controls_GetCvarDefault( "cg_autoswitch" ); s_controls.autoswitch.curvalue = Controls_GetCvarDefault( "cg_autoswitch" );
s_controls.sensitivity.curvalue = Controls_GetCvarDefault( "sensitivity" ); s_controls.sensitivity.curvalue = Controls_GetCvarDefault( "sensitivity" );
s_controls.joyenable.curvalue = Controls_GetCvarDefault( "in_joystick" );
s_controls.joythreshold.curvalue = Controls_GetCvarDefault( "joy_threshold" );
s_controls.freelook.curvalue = Controls_GetCvarDefault( "cl_freelook" ); s_controls.freelook.curvalue = Controls_GetCvarDefault( "cl_freelook" );
} }
@ -1118,8 +1104,6 @@ static void Controls_MenuEvent( void* ptr, int event )
case ID_SMOOTHMOUSE: case ID_SMOOTHMOUSE:
case ID_ALWAYSRUN: case ID_ALWAYSRUN:
case ID_AUTOSWITCH: case ID_AUTOSWITCH:
case ID_JOYENABLE:
case ID_JOYTHRESHOLD:
if (event == QM_ACTIVATED) if (event == QM_ACTIVATED)
{ {
s_controls.changesmade = qtrue; s_controls.changesmade = qtrue;
@ -1535,24 +1519,6 @@ static void Controls_MenuInit( void )
s_controls.chat4.generic.ownerdraw = Controls_DrawKeyBinding; s_controls.chat4.generic.ownerdraw = Controls_DrawKeyBinding;
s_controls.chat4.generic.id = ID_CHAT4; s_controls.chat4.generic.id = ID_CHAT4;
s_controls.joyenable.generic.type = MTYPE_RADIOBUTTON;
s_controls.joyenable.generic.flags = QMF_SMALLFONT;
s_controls.joyenable.generic.x = SCREEN_WIDTH/2;
s_controls.joyenable.generic.name = "joystick";
s_controls.joyenable.generic.id = ID_JOYENABLE;
s_controls.joyenable.generic.callback = Controls_MenuEvent;
s_controls.joyenable.generic.statusbar = Controls_StatusBar;
s_controls.joythreshold.generic.type = MTYPE_SLIDER;
s_controls.joythreshold.generic.x = SCREEN_WIDTH/2;
s_controls.joythreshold.generic.flags = QMF_SMALLFONT;
s_controls.joythreshold.generic.name = "joystick threshold";
s_controls.joythreshold.generic.id = ID_JOYTHRESHOLD;
s_controls.joythreshold.generic.callback = Controls_MenuEvent;
s_controls.joythreshold.minvalue = 0.05f;
s_controls.joythreshold.maxvalue = 0.75f;
s_controls.joythreshold.generic.statusbar = Controls_StatusBar;
s_controls.name.generic.type = MTYPE_PTEXT; s_controls.name.generic.type = MTYPE_PTEXT;
s_controls.name.generic.flags = QMF_CENTER_JUSTIFY|QMF_INACTIVE; s_controls.name.generic.flags = QMF_CENTER_JUSTIFY|QMF_INACTIVE;
s_controls.name.generic.x = 320; s_controls.name.generic.x = 320;
@ -1581,8 +1547,6 @@ static void Controls_MenuInit( void )
Menu_AddItem( &s_controls.menu, &s_controls.freelook ); Menu_AddItem( &s_controls.menu, &s_controls.freelook );
Menu_AddItem( &s_controls.menu, &s_controls.centerview ); Menu_AddItem( &s_controls.menu, &s_controls.centerview );
Menu_AddItem( &s_controls.menu, &s_controls.zoomview ); Menu_AddItem( &s_controls.menu, &s_controls.zoomview );
Menu_AddItem( &s_controls.menu, &s_controls.joyenable );
Menu_AddItem( &s_controls.menu, &s_controls.joythreshold );
Menu_AddItem( &s_controls.menu, &s_controls.alwaysrun ); Menu_AddItem( &s_controls.menu, &s_controls.alwaysrun );
Menu_AddItem( &s_controls.menu, &s_controls.run ); Menu_AddItem( &s_controls.menu, &s_controls.run );