- The reorganized DirectInput game controller code finally compiles. (Ugh! It

took far too long to reach this point.) Manual axis configuration is
  currently disabled, since I need to rewrite that, too. The eventual point of
  this is that the code will be modular enough that I can just plop in
  routines for XInput controllers and driver-less PlayStation 2 adapters
  without much fuss, since the old joystick code was very much DirectInput-
  centric.


SVN r1672 (trunk)
This commit is contained in:
Randy Heit 2009-06-20 03:16:08 +00:00
parent e11cac7e89
commit a5b118cf7c
12 changed files with 1371 additions and 735 deletions

View file

@ -1,4 +1,13 @@
June 19, 2009 (Changes by Graf Zahl)
June 19, 2009
- The reorganized DirectInput game controller code finally compiles. (Ugh! It
took far too long to reach this point.) Manual axis configuration is
currently disabled, since I need to rewrite that, too. The eventual point of
this is that the code will be modular enough that I can just plop in
routines for XInput controllers and driver-less PlayStation 2 adapters
without much fuss, since the old joystick code was very much DirectInput-
centric.
June 19, 2009 (Changes by Graf Zahl)
- Changed AWeaponGiver to keep the weapon actor around instead of respawning a new
one for each call.
- Fixed: AWeaponGiver::TryPickup checked the wrong item for ammo to give.

View file

@ -111,7 +111,8 @@ if( WIN32 )
comctl32
comdlg32
ws2_32
setupapi )
setupapi
oleaut32 )
else( WIN32 )
option( NO_GTK "Disable GTK+ dialogs (Not applicable to Windows)" )
option( VALGRIND "Add special Valgrind sequences to self-modifying code" )
@ -400,6 +401,7 @@ if( WIN32 )
win32/i_input.cpp
win32/i_keyboard.cpp
win32/i_mouse.cpp
win32/i_dijoy.cpp
win32/i_main.cpp
win32/i_movie.cpp
win32/i_system.cpp

View file

@ -172,13 +172,17 @@ enum ESkillLevels
#define NUM_KEYS 0x19C
#define JOYAXIS_NONE 0
#define JOYAXIS_YAW 1
#define JOYAXIS_PITCH 2
#define JOYAXIS_FORWARD 3
#define JOYAXIS_SIDE 4
#define JOYAXIS_UP 5
//#define JOYAXIS_ROLL 6 // Ha ha. No roll for you.
enum EJoyAxis
{
JOYAXIS_None = -1,
JOYAXIS_Yaw,
JOYAXIS_Pitch,
JOYAXIS_Forward,
JOYAXIS_Side,
JOYAXIS_Up,
// JOYAXIS_Roll, // Ha ha. No roll for you.
NUM_JOYAXIS,
};
// [RH] dmflags bits (based on Q2's)
enum

View file

@ -207,8 +207,6 @@ EXTERN_CVAR (Bool, developer)
extern bool ToggleFullscreen;
extern float JoyAxes[6];
extern int Net_Arbitrator;
EXTERN_CVAR (Bool, var_friction)

View file

@ -41,6 +41,7 @@
#include "m_random.h"
#include "m_crc32.h"
#include "i_system.h"
#include "i_input.h"
#include "p_saveg.h"
#include "p_tick.h"
#include "d_main.h"
@ -575,22 +576,39 @@ void G_BuildTiccmd (ticcmd_t *cmd)
if (Button_MoveUp.bDown) cmd->ucmd.buttons |= BT_MOVEUP;
if (Button_ShowScores.bDown) cmd->ucmd.buttons |= BT_SHOWSCORES;
// [RH] Scale joystick moves to full range of allowed speeds
if (JoyAxes[JOYAXIS_PITCH] != 0)
// Handle joysticks/game controllers.
float joyaxes[NUM_JOYAXIS];
I_GetAxes(joyaxes);
// Remap some axes depending on button state.
if (Button_Strafe.bDown || (Button_Mlook.bDown && lookstrafe))
{
G_AddViewPitch (int((JoyAxes[JOYAXIS_PITCH] * 2048) / 256));
joyaxes[JOYAXIS_Side] = -joyaxes[JOYAXIS_Yaw];
joyaxes[JOYAXIS_Yaw] = 0;
}
if (Button_Mlook.bDown)
{
joyaxes[JOYAXIS_Pitch] = joyaxes[JOYAXIS_Forward];
joyaxes[JOYAXIS_Forward] = 0;
}
if (joyaxes[JOYAXIS_Pitch] != 0)
{
G_AddViewPitch(int(joyaxes[JOYAXIS_Pitch] * 2048));
LocalKeyboardTurner = true;
}
if (JoyAxes[JOYAXIS_YAW] != 0)
if (joyaxes[JOYAXIS_Yaw] != 0)
{
G_AddViewAngle (int((-1280 * JoyAxes[JOYAXIS_YAW]) / 256));
G_AddViewAngle(int(-1280 * joyaxes[JOYAXIS_Yaw]));
LocalKeyboardTurner = true;
}
side += int((MAXPLMOVE * JoyAxes[JOYAXIS_SIDE]) / 256);
forward += int((JoyAxes[JOYAXIS_FORWARD] * MAXPLMOVE) / 256);
fly += int(JoyAxes[JOYAXIS_UP] * 8);
side += int(MAXPLMOVE * joyaxes[JOYAXIS_Side]);
forward += int(joyaxes[JOYAXIS_Forward] * MAXPLMOVE);
fly += int(joyaxes[JOYAXIS_Up] * 2048);
// Handle mice.
if (!Button_Mlook.bDown && !freelook)
{
forward += (int)((float)mousey * m_forward);
@ -609,6 +627,7 @@ void G_BuildTiccmd (ticcmd_t *cmd)
mousex = mousey = 0;
// Build command.
if (forward > MAXPLMOVE)
forward = MAXPLMOVE;
else if (forward < -MAXPLMOVE)

View file

@ -290,6 +290,7 @@ menu_t MouseMenu =
*=======================================*/
EXTERN_CVAR (Bool, use_joystick)
#if 0
EXTERN_CVAR (Float, joy_speedmultiplier)
EXTERN_CVAR (Int, joy_xaxis)
EXTERN_CVAR (Int, joy_yaxis)
@ -313,6 +314,7 @@ EXTERN_CVAR (Float, joy_forwardspeed)
EXTERN_CVAR (Float, joy_sidespeed)
EXTERN_CVAR (Float, joy_upspeed)
EXTERN_CVAR (GUID, joy_guid)
#endif
static value_t JoyAxisMapNames[6] =
{
@ -332,9 +334,11 @@ static value_t Inversion[2] =
static menuitem_t JoystickItems[] =
{
#if 0
{ discrete, "Enable joystick", {&use_joystick}, {2.0}, {0.0}, {0.0}, {YesNo} },
{ discrete_guid,"Active joystick", {&joy_guid}, {0.0}, {0.0}, {0.0}, {NULL} },
{ slider, "Overall sensitivity", {&joy_speedmultiplier}, {0.9f}, {2.0}, {0.2f}, {NULL} },
#endif
{ redtext, " ", {NULL}, {0.0}, {0.0}, {0.0}, {NULL} },
{ whitetext,"Axis Assignments", {NULL}, {0.0}, {0.0}, {0.0}, {NULL} },
{ redtext, " ", {NULL}, {0.0}, {0.0}, {0.0}, {NULL} },
@ -1629,6 +1633,7 @@ int M_FindCurVal (float cur, valuestring_t *values, int numvals)
return v;
}
#if 0
int M_FindCurGUID (const GUID &guid, GUIDName *values, int numvals)
{
int v;
@ -1639,6 +1644,7 @@ int M_FindCurGUID (const GUID &guid, GUIDName *values, int numvals)
return v;
}
#endif
const char *M_FindCurVal(const char *cur, valueenum_t *values, int numvals)
{
@ -1896,6 +1902,7 @@ void M_OptDrawer ()
}
break;
#if 0
case discrete_guid:
{
int v, vals;
@ -1916,6 +1923,7 @@ void M_OptDrawer ()
}
break;
#endif
case nochoice:
screen->DrawText (SmallFont, CR_GOLD, indent + 14, y,
@ -2409,6 +2417,7 @@ void M_OptResponder (event_t *ev)
S_Sound (CHAN_VOICE | CHAN_UI, "menu/change", 1, ATTN_NONE);
break;
#if 0
case discrete_guid:
{
int cur;
@ -2423,6 +2432,7 @@ void M_OptResponder (event_t *ev)
}
S_Sound (CHAN_VOICE | CHAN_UI, "menu/change", 1, ATTN_NONE);
break;
#endif
case inverter:
value = item->a.cvar->GetGenericRep (CVAR_Float);
@ -2558,6 +2568,7 @@ void M_OptResponder (event_t *ev)
S_Sound (CHAN_VOICE | CHAN_UI, "menu/change", 1, ATTN_NONE);
break;
#if 0
case discrete_guid:
{
int cur;
@ -2572,6 +2583,7 @@ void M_OptResponder (event_t *ev)
}
S_Sound (CHAN_VOICE | CHAN_UI, "menu/change", 1, ATTN_NONE);
break;
#endif
case inverter:
value = item->a.cvar->GetGenericRep (CVAR_Float);
@ -2983,6 +2995,7 @@ CCMD (menu_mouse)
void UpdateJoystickMenu ()
{
#if 0
static FIntCVar * const cvars[8] =
{
&joy_xaxis, &joy_yaxis, &joy_zaxis,
@ -3090,6 +3103,7 @@ void UpdateJoystickMenu ()
{
CalcIndent (&JoystickMenu);
}
#endif
}
static void JoystickOptions ()

View file

@ -30,112 +30,7 @@ CVAR (Bool, use_mouse, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Bool, m_noprescale, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Bool, m_filter, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Bool, sdl_nokeyrepeat, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
float JoyAxes[6];
//static int JoyActive;
//static BYTE JoyButtons[128];
//static BYTE JoyPOV[4];
static BYTE JoyAxisMap[8];
static float JoyAxisThresholds[8];
char *JoyAxisNames[8];
static const BYTE POVButtons[9] = { 0x01, 0x03, 0x02, 0x06, 0x04, 0x0C, 0x08, 0x09, 0x00 };
TArray<GUIDName> JoystickNames;
CVAR (Bool, use_joystick, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (GUID, joy_guid, NULL, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL)
static void MapAxis (FIntCVar &var, int num)
{
if (var < JOYAXIS_NONE || var > JOYAXIS_UP)
{
var = JOYAXIS_NONE;
}
else
{
JoyAxisMap[num] = var;
}
}
CUSTOM_CVAR (Int, joy_xaxis, JOYAXIS_YAW, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 0);
}
CUSTOM_CVAR (Int, joy_yaxis, JOYAXIS_FORWARD, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 1);
}
CUSTOM_CVAR (Int, joy_zaxis, JOYAXIS_SIDE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 2);
}
CUSTOM_CVAR (Int, joy_xrot, JOYAXIS_NONE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 3);
}
CUSTOM_CVAR (Int, joy_yrot, JOYAXIS_NONE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 4);
}
CUSTOM_CVAR (Int, joy_zrot, JOYAXIS_PITCH, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 5);
}
CUSTOM_CVAR (Int, joy_slider, JOYAXIS_NONE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 6);
}
CUSTOM_CVAR (Int, joy_dial, JOYAXIS_NONE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 7);
}
CUSTOM_CVAR (Float, joy_xthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[0] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_ythreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[1] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_zthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[2] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_xrotthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[3] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_yrotthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[4] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_zrotthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[5] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_sliderthreshold, 0.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[6] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_dialthreshold, 0.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[7] = clamp (self * 256.f, 0.f, 256.f);
}
CVAR (Float, joy_speedmultiplier,1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_yawspeed, -1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_pitchspeed, -.75f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_forwardspeed, -1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_sidespeed, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_upspeed, -1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
static FBaseCVar * const JoyConfigVars[] =
{
&joy_xaxis, &joy_yaxis, &joy_zaxis, &joy_xrot, &joy_yrot, &joy_zrot, &joy_slider, &joy_dial,
&joy_xthreshold, &joy_ythreshold, &joy_zthreshold, &joy_xrotthreshold, &joy_yrotthreshold, &joy_zrotthreshold, &joy_sliderthreshold, &joy_dialthreshold,
&joy_speedmultiplier, &joy_yawspeed, &joy_pitchspeed, &joy_forwardspeed, &joy_sidespeed,
&joy_upspeed
};
CVAR (Bool, use_joystick, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
EXTERN_CVAR (Bool, fullscreen)

1237
src/win32/i_dijoy.cpp Normal file

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,7 @@
** Handles input from keyboard, mouse, and joystick
**
**---------------------------------------------------------------------------
** Copyright 1998-2006 Randy Heit
** Copyright 1998-2009 Randy Heit
** All rights reserved.
**
** Redistribution and use in source and binary forms, with or without
@ -47,8 +47,8 @@
#endif
#include <windows.h>
#include <mmsystem.h>
#include <dbt.h>
#include <dinput.h>
#include <malloc.h>
#include <stdio.h>
#include <stdlib.h>
@ -128,8 +128,6 @@ extern bool SpawnEAXWindow;
static HMODULE DInputDLL;
static HRESULT InitJoystick ();
bool GUICapture;
extern FMouse *Mouse;
extern FKeyboard *Keyboard;
@ -141,11 +139,9 @@ extern BOOL vidactive;
extern HWND Window, ConWindow;
extern HWND EAXEditWindow;
extern void UpdateJoystickMenu ();
extern menu_t JoystickMenu;
EXTERN_CVAR (String, language)
EXTERN_CVAR (Bool, lookstrafe)
EXTERN_CVAR (Bool, use_joystick)
static int WheelDelta;
@ -155,151 +151,12 @@ static bool noidle = false;
LPDIRECTINPUT8 g_pdi;
LPDIRECTINPUT g_pdi3;
static LPDIRECTINPUTDEVICE8 g_pJoy;
TArray<GUIDName> JoystickNames;
static DIDEVCAPS JoystickCaps;
float JoyAxes[6];
static int JoyActive;
static BYTE JoyButtons[128];
static BYTE JoyPOV[4];
static BYTE JoyAxisMap[8];
static float JoyAxisThresholds[8];
char *JoyAxisNames[8];
static const size_t Axes[8] =
{
myoffsetof(DIJOYSTATE2,lX),
myoffsetof(DIJOYSTATE2,lY),
myoffsetof(DIJOYSTATE2,lZ),
myoffsetof(DIJOYSTATE2,lRx),
myoffsetof(DIJOYSTATE2,lRy),
myoffsetof(DIJOYSTATE2,lRz),
myoffsetof(DIJOYSTATE2,rglSlider[0]),
myoffsetof(DIJOYSTATE2,rglSlider[1])
};
static const BYTE POVButtons[9] = { 0x01, 0x03, 0x02, 0x06, 0x04, 0x0C, 0x08, 0x09, 0x00 };
BOOL AppActive = TRUE;
int SessionState = 0;
CVAR (Bool, use_joystick, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CUSTOM_CVAR (GUID, joy_guid, NULL, CVAR_ARCHIVE|CVAR_GLOBALCONFIG|CVAR_NOINITCALL)
{
if (g_pJoy != NULL)
{
DIDEVICEINSTANCE inst = { sizeof(DIDEVICEINSTANCE), };
if (SUCCEEDED(g_pJoy->GetDeviceInfo (&inst)) && self != inst.guidInstance)
{
DI_InitJoy ();
UpdateJoystickMenu ();
}
}
else
{
DI_InitJoy ();
UpdateJoystickMenu ();
}
}
static void MapAxis (FIntCVar &var, int num)
{
if (var < JOYAXIS_NONE || var > JOYAXIS_UP)
{
var = JOYAXIS_NONE;
}
else
{
JoyAxisMap[num] = var;
}
}
CUSTOM_CVAR (Int, joy_xaxis, JOYAXIS_YAW, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 0);
}
CUSTOM_CVAR (Int, joy_yaxis, JOYAXIS_FORWARD, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 1);
}
CUSTOM_CVAR (Int, joy_zaxis, JOYAXIS_SIDE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 2);
}
CUSTOM_CVAR (Int, joy_xrot, JOYAXIS_NONE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 3);
}
CUSTOM_CVAR (Int, joy_yrot, JOYAXIS_NONE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 4);
}
CUSTOM_CVAR (Int, joy_zrot, JOYAXIS_PITCH, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 5);
}
CUSTOM_CVAR (Int, joy_slider, JOYAXIS_NONE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 6);
}
CUSTOM_CVAR (Int, joy_dial, JOYAXIS_NONE, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
MapAxis (self, 7);
}
CUSTOM_CVAR (Float, joy_xthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[0] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_ythreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[1] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_zthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[2] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_xrotthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[3] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_yrotthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[4] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_zrotthreshold, 0.15f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[5] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_sliderthreshold, 0.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[6] = clamp (self * 256.f, 0.f, 256.f);
}
CUSTOM_CVAR (Float, joy_dialthreshold, 0.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
JoyAxisThresholds[7] = clamp (self * 256.f, 0.f, 256.f);
}
CVAR (Float, joy_speedmultiplier,1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_yawspeed, -1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_pitchspeed, -.75f,CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_forwardspeed, -1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_sidespeed, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Float, joy_upspeed, -1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CVAR (Bool, k_allowfullscreentoggle, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
static FBaseCVar * const JoyConfigVars[] =
{
&joy_xaxis, &joy_yaxis, &joy_zaxis, &joy_xrot, &joy_yrot, &joy_zrot, &joy_slider, &joy_dial,
&joy_xthreshold, &joy_ythreshold, &joy_zthreshold, &joy_xrotthreshold, &joy_yrotthreshold, &joy_zrotthreshold, &joy_sliderthreshold, &joy_dialthreshold,
&joy_speedmultiplier, &joy_yawspeed, &joy_pitchspeed, &joy_forwardspeed, &joy_sidespeed,
&joy_upspeed
};
extern int chatmodeon;
static void I_CheckGUICapture ()
@ -498,15 +355,18 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
return result;
}
for (int i = 0; i < NUM_JOYDEVICES; ++i)
{
if (CallHook(JoyDevices[i], hWnd, message, wParam, lParam, &result))
{
return result;
}
}
if (GUICapture && GUIWndProcHook(hWnd, message, wParam, lParam, &result))
{
return result;
}
event_t event;
memset (&event, 0, sizeof(event));
switch (message)
{
case WM_DESTROY:
@ -669,74 +529,6 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
}
break;
case WM_DEVICECHANGE:
if (wParam == DBT_DEVNODES_CHANGED ||
wParam == DBT_DEVICEARRIVAL ||
wParam == DBT_CONFIGCHANGED)
{
unsigned int i;
TArray<GUID> oldjoys;
for (i = 0; i < JoystickNames.Size(); ++i)
{
oldjoys.Push (JoystickNames[i].ID);
}
DI_EnumJoy ();
// If a new joystick was added and the joystick menu is open,
// switch to it.
if (menuactive != MENU_Off && CurrentMenu == &JoystickMenu)
{
for (i = 0; i < JoystickNames.Size(); ++i)
{
bool wasListed = false;
for (unsigned int j = 0; j < oldjoys.Size(); ++j)
{
if (oldjoys[j] == JoystickNames[i].ID)
{
wasListed = true;
break;
}
}
if (!wasListed)
{
joy_guid = JoystickNames[i].ID;
break;
}
}
}
// If the current joystick was removed,
// try to switch to a different one.
if (g_pJoy != NULL)
{
DIDEVICEINSTANCE inst = { sizeof(DIDEVICEINSTANCE), };
if (SUCCEEDED(g_pJoy->GetDeviceInfo (&inst)))
{
for (i = 0; i < JoystickNames.Size(); ++i)
{
if (JoystickNames[i].ID == inst.guidInstance)
{
break;
}
}
if (i == JoystickNames.Size ())
{
DI_InitJoy ();
}
}
}
else
{
DI_InitJoy ();
}
UpdateJoystickMenu ();
}
break;
case WM_PALETTECHANGED:
if ((HWND)wParam == Window)
break;
@ -763,376 +555,6 @@ LRESULT CALLBACK WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return 0;
}
/****** Joystick stuff ******/
void DI_JoyCheck ()
{
float mul;
event_t event;
HRESULT hr;
DIJOYSTATE2 js;
int i;
BYTE pov;
if (g_pJoy == NULL)
{
return;
}
hr = g_pJoy->Poll ();
if (FAILED(hr))
{
do
{
hr = g_pJoy->Acquire ();
}
while (hr == DIERR_INPUTLOST);
if (FAILED(hr))
return;
}
hr = g_pJoy->GetDeviceState (sizeof(DIJOYSTATE2), &js);
if (FAILED(hr))
return;
mul = joy_speedmultiplier;
if (Button_Speed.bDown)
{
mul *= 0.5f;
}
for (i = 0; i < 6; ++i)
{
JoyAxes[i] = 0.f;
}
for (i = 0; i < 8; ++i)
{
int vaxis = JoyAxisMap[i];
if (vaxis != JOYAXIS_NONE)
{
if (vaxis == JOYAXIS_YAW && (Button_Strafe.bDown ||
(Button_Mlook.bDown && lookstrafe)))
{
vaxis = JOYAXIS_SIDE;
}
else if (vaxis == JOYAXIS_FORWARD && Button_Mlook.bDown)
{
vaxis = JOYAXIS_PITCH;
}
float axisval = *((LONG *)((BYTE *)&js + Axes[i]));
if (fabsf(axisval) > JoyAxisThresholds[i])
{
if (axisval > 0.f)
{
axisval -= JoyAxisThresholds[i];
}
else
{
axisval += JoyAxisThresholds[i];
}
JoyAxes[vaxis] += axisval * mul * 256.f / (256.f - JoyAxisThresholds[i]);
}
}
}
JoyAxes[JOYAXIS_YAW] *= joy_yawspeed;
JoyAxes[JOYAXIS_PITCH] *= joy_pitchspeed;
JoyAxes[JOYAXIS_FORWARD] *= joy_forwardspeed;
JoyAxes[JOYAXIS_SIDE] *= joy_sidespeed;
JoyAxes[JOYAXIS_UP] *= joy_upspeed;
event.data2 = event.data3 = 0;
// Send button up/down events
for (i = 0; i < 128; ++i)
{
if ((js.rgbButtons[i] ^ JoyButtons[i]) & 0x80)
{
event.data1 = KEY_FIRSTJOYBUTTON + i;
if (JoyButtons[i])
{
event.type = EV_KeyUp;
JoyButtons[i] = 0;
}
else
{
event.type = EV_KeyDown;
JoyButtons[i] = 0x80;
}
D_PostEvent (&event);
}
}
for (i = 0; i < 4; ++i)
{
if (LOWORD(js.rgdwPOV[i]) == 0xFFFF)
{
pov = 8;
}
else
{
pov = ((js.rgdwPOV[i] + 2250) % 36000) / 4500;
}
pov = POVButtons[pov];
for (int j = 0; j < 4; ++j)
{
BYTE mask = 1 << j;
if ((JoyPOV[i] ^ pov) & mask)
{
event.data1 = KEY_JOYPOV1_UP + i*4 + j;
event.type = (pov & mask) ? EV_KeyDown : EV_KeyUp;
D_PostEvent (&event);
}
}
JoyPOV[i] = pov;
}
}
bool SetJoystickSection (bool create)
{
DIDEVICEINSTANCE inst = { sizeof(DIDEVICEINSTANCE), };
char section[80] = "Joystick.";
if (g_pJoy != NULL && SUCCEEDED(g_pJoy->GetDeviceInfo (&inst)))
{
FormatGUID (section + 9, countof(section) - 9, inst.guidInstance);
strcpy (section + 9 + 38, ".Axes");
return GameConfig->SetSection (section, create);
}
else
{
return false;
}
}
void LoadJoystickConfig ()
{
if (SetJoystickSection (false))
{
for (size_t i = 0; i < countof(JoyConfigVars); ++i)
{
const char *val = GameConfig->GetValueForKey (JoyConfigVars[i]->GetName());
UCVarValue cval;
if (val != NULL)
{
cval.String = const_cast<char *>(val);
JoyConfigVars[i]->SetGenericRep (cval, CVAR_String);
}
}
}
}
void SaveJoystickConfig ()
{
if (SetJoystickSection (true))
{
GameConfig->ClearCurrentSection ();
for (size_t i = 0; i < countof(JoyConfigVars); ++i)
{
UCVarValue cval = JoyConfigVars[i]->GetGenericRep (CVAR_String);
GameConfig->SetValueForKey (JoyConfigVars[i]->GetName(), cval.String);
}
}
}
BOOL CALLBACK EnumJoysticksCallback (LPCDIDEVICEINSTANCE lpddi, LPVOID pvRef)
{
GUIDName name;
JoyActive++;
name.ID = lpddi->guidInstance;
name.Name = copystring (lpddi->tszInstanceName);
JoystickNames.Push (name);
return DIENUM_CONTINUE;
}
void DI_EnumJoy ()
{
unsigned int i;
for (i = 0; i < JoystickNames.Size(); ++i)
{
delete[] JoystickNames[i].Name;
}
JoyActive = 0;
JoystickNames.Clear ();
if (g_pdi != NULL && !Args->CheckParm ("-nojoy"))
{
g_pdi->EnumDevices (DI8DEVCLASS_GAMECTRL, EnumJoysticksCallback, NULL, DIEDFL_ALLDEVICES);
}
}
BOOL DI_InitJoy (void)
{
HRESULT hr;
unsigned int i;
if (g_pdi == NULL)
{
return TRUE;
}
if (g_pJoy != NULL)
{
SaveJoystickConfig ();
g_pJoy->Release ();
g_pJoy = NULL;
}
if (JoystickNames.Size() == 0)
{
return TRUE;
}
// Try to obtain the joystick specified by joy_guid
for (i = 0; i < JoystickNames.Size(); ++i)
{
if (JoystickNames[i].ID == joy_guid)
{
hr = g_pdi->CreateDevice (JoystickNames[i].ID, &g_pJoy, NULL);
if (FAILED(hr))
{
i = JoystickNames.Size();
}
break;
}
}
// If the preferred joystick could not be obtained, grab the first
// one available.
if (i == JoystickNames.Size())
{
for (i = 0; i <= JoystickNames.Size(); ++i)
{
hr = g_pdi->CreateDevice (JoystickNames[i].ID, &g_pJoy, NULL);
if (SUCCEEDED(hr))
{
break;
}
}
}
if (i == JoystickNames.Size())
{
JoyActive = 0;
return TRUE;
}
if (FAILED (InitJoystick ()))
{
JoyActive = 0;
g_pJoy->Release ();
g_pJoy = NULL;
}
else
{
LoadJoystickConfig ();
joy_guid = JoystickNames[i].ID;
}
return TRUE;
}
BOOL CALLBACK EnumAxesCallback (LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef)
{
DIPROPRANGE diprg =
{
{
sizeof (DIPROPRANGE),
sizeof (DIPROPHEADER),
lpddoi->dwType,
DIPH_BYID
},
-256,
+256
};
if (lpddoi->wUsagePage == 1)
{
if (lpddoi->wUsage >= 0x30 && lpddoi->wUsage <= 0x37)
{
JoyAxisNames[lpddoi->wUsage-0x30] = copystring (lpddoi->tszName);
}
}
if (FAILED(g_pJoy->SetProperty (DIPROP_RANGE, &diprg.diph)))
{
return DIENUM_STOP;
}
else
{
return DIENUM_CONTINUE;
}
}
static HRESULT InitJoystick ()
{
HRESULT hr;
memset (JoyPOV, 9, sizeof(JoyPOV));
for (int i = 0; i < 8; ++i)
{
if (JoyAxisNames[i])
{
delete[] JoyAxisNames[i];
JoyAxisNames[i] = NULL;
}
}
hr = g_pJoy->SetDataFormat (&c_dfDIJoystick2);
if (FAILED(hr))
{
Printf (PRINT_BOLD, "Could not set joystick data format.\n");
return hr;
}
hr = g_pJoy->SetCooperativeLevel (Window, DISCL_EXCLUSIVE|DISCL_FOREGROUND);
if (FAILED(hr))
{
Printf (PRINT_BOLD, "Could not set joystick cooperative level.\n");
return hr;
}
JoystickCaps.dwSize = sizeof(JoystickCaps);
hr = g_pJoy->GetCapabilities (&JoystickCaps);
if (FAILED(hr))
{
Printf (PRINT_BOLD, "Could not query joystick capabilities.\n");
return hr;
}
hr = g_pJoy->EnumObjects (EnumAxesCallback, NULL, DIDFT_AXIS);
if (FAILED(hr))
{
Printf (PRINT_BOLD, "Could not set joystick axes ranges.\n");
return hr;
}
g_pJoy->Acquire ();
return S_OK;
}
/****** Stuff from Andy Bay's mymouse.c ******/
/****************************************************************************
*
* DIInit
*
* Initialize the DirectInput variables.
*
****************************************************************************/
// [RH] Used to obtain DirectInput access to the mouse.
// (Preferred for Win95, but buggy under NT 4.)
bool I_InitInput (void *hwnd)
{
HRESULT hr;
@ -1198,8 +620,7 @@ bool I_InitInput (void *hwnd)
I_StartupMouse();
Printf ("I_StartupJoystick\n");
DI_EnumJoy ();
DI_InitJoy ();
I_StartupJoystick();
Printf ("I_StartupKeyboard\n");
I_StartupKeyboard();
@ -1221,11 +642,13 @@ void I_ShutdownInput ()
delete Mouse;
Mouse = NULL;
}
if (g_pJoy)
for (int i = 0; i < NUM_JOYDEVICES; ++i)
{
SaveJoystickConfig ();
g_pJoy->Release ();
g_pJoy = NULL;
if (JoyDevices[i] != NULL)
{
delete JoyDevices[i];
JoyDevices[i] = NULL;
}
}
if (g_pdi)
{
@ -1273,7 +696,6 @@ void I_GetEvent ()
}
}
//
// I_StartTic
//
@ -1292,7 +714,33 @@ void I_StartFrame ()
{
if (use_joystick)
{
DI_JoyCheck ();
for (int i = 0; i < NUM_JOYDEVICES; ++i)
{
if (JoyDevices[i] != NULL)
{
JoyDevices[i]->ProcessInput();
}
}
}
}
void I_GetAxes(float axes[NUM_JOYAXIS])
{
int i;
for (i = 0; i < NUM_JOYAXIS; ++i)
{
axes[i] = 0;
}
if (use_joystick)
{
for (i = 0; i < NUM_JOYDEVICES; ++i)
{
if (JoyDevices[i] != NULL)
{
JoyDevices[i]->AddAxes(axes);
}
}
}
}

View file

@ -35,24 +35,15 @@
#define __I_INPUT_H__
#include "doomtype.h"
#include "doomdef.h"
bool I_InitInput (void *hwnd);
void I_ShutdownInput ();
void I_PutInClipboard (const char *str);
FString I_GetFromClipboard (bool windows_has_no_selection_clipboard);
void I_GetEvent ();
struct GUIDName
{
GUID ID;
char *Name;
};
extern TArray<GUIDName> JoystickNames;
extern char *JoyAxisNames[8];
extern void DI_EnumJoy ();
void I_GetEvent();
void I_GetAxes(float axes[NUM_JOYAXIS]);
#ifdef USE_WINDOWS_DWORD
// Don't make these definitions available to the main body of the source code.
@ -118,9 +109,26 @@ protected:
void PostKeyEvent(int keynum, INTBOOL down, bool foreground);
};
class FJoystickCollection : public FInputDevice
{
public:
virtual void AddAxes(float axes[NUM_JOYAXIS]) = 0;
};
enum
{
INPUT_DIJoy,
INPUT_XInput,
INPUT_PS2EMS,
NUM_JOYDEVICES
};
extern FJoystickCollection *JoyDevices[NUM_JOYDEVICES];
void I_StartupMouse();
void I_CheckNativeMouse(bool prefer_native);
void I_StartupKeyboard();
void I_StartupJoystick();
// USB HID usage page numbers
#define HID_GENERIC_DESKTOP_PAGE 0x01

View file

@ -98,8 +98,6 @@ class Win32Video : public IVideo
bool m_IteratorFS;
bool m_IsFullscreen;
bool m_CalledCoInitialize;
void AddMode (int x, int y, int bits, int baseHeight, int doubling);
void FreeModes ();

View file

@ -1968,6 +1968,10 @@
RelativePath="src\win32\i_crash.cpp"
>
</File>
<File
RelativePath=".\src\win32\i_dijoy.cpp"
>
</File>
<File
RelativePath=".\src\win32\i_input.cpp"
>