- Make joystick input in the background CVAR controlled.

This commit is contained in:
drfrag 2019-07-03 20:52:03 +02:00
parent f340d411c3
commit c3482b75fc
2 changed files with 22 additions and 2 deletions

View file

@ -33,12 +33,18 @@
#include <SDL.h> #include <SDL.h>
#include "doomdef.h" #include "doomdef.h"
#include "version.h"
#include "templates.h" #include "templates.h"
#include "m_joy.h" #include "m_joy.h"
// Very small deadzone so that floating point magic doesn't happen // Very small deadzone so that floating point magic doesn't happen
#define MIN_DEADZONE 0.000001f #define MIN_DEADZONE 0.000001f
CUSTOM_CVAR(Bool, joy_background, false, CVAR_GLOBALCONFIG|CVAR_ARCHIVE|CVAR_NOINITCALL)
{
Printf("This won't take effect until " GAMENAME " is restarted.\n");
}
class SDLInputJoystick: public IJoystickConfig class SDLInputJoystick: public IJoystickConfig
{ {
public: public:
@ -298,7 +304,8 @@ static SDLInputJoystickManager *JoystickManager;
void I_StartupJoysticks() void I_StartupJoysticks()
{ {
SDL_SetHint("SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS", "1"); if (joy_background)
SDL_SetHint("SDL_JOYSTICK_ALLOW_BACKGROUND_EVENTS", "1");
if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) >= 0) if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) >= 0)
JoystickManager = new SDLInputJoystickManager(); JoystickManager = new SDLInputJoystickManager();
} }

View file

@ -52,6 +52,7 @@
#include "c_dispatch.h" #include "c_dispatch.h"
#include "doomdef.h" #include "doomdef.h"
#include "doomstat.h" #include "doomstat.h"
#include "version.h"
#include "win32iface.h" #include "win32iface.h"
#include "templates.h" #include "templates.h"
#include "gameconfigfile.h" #include "gameconfigfile.h"
@ -286,6 +287,11 @@ CUSTOM_CVAR(Bool, joy_dinput, true, CVAR_GLOBALCONFIG|CVAR_ARCHIVE|CVAR_NOINITCA
D_PostEvent(&ev); D_PostEvent(&ev);
} }
CUSTOM_CVAR(Bool, joy_background, false, CVAR_GLOBALCONFIG|CVAR_ARCHIVE|CVAR_NOINITCALL)
{
Printf("This won't take effect until " GAMENAME " is restarted.\n");
}
// PRIVATE DATA DEFINITIONS ------------------------------------------------ // PRIVATE DATA DEFINITIONS ------------------------------------------------
static const uint8_t POVButtons[9] = { 0x01, 0x03, 0x02, 0x06, 0x04, 0x0C, 0x08, 0x09, 0x00 }; static const uint8_t POVButtons[9] = { 0x01, 0x03, 0x02, 0x06, 0x04, 0x0C, 0x08, 0x09, 0x00 };
@ -389,7 +395,14 @@ bool FDInputJoystick::GetDevice()
Printf(TEXTCOLOR_ORANGE "Setting data format for %s failed.\n", Name.GetChars()); Printf(TEXTCOLOR_ORANGE "Setting data format for %s failed.\n", Name.GetChars());
return false; return false;
} }
hr = Device->SetCooperativeLevel(Window, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND); if (joy_background)
{
hr = Device->SetCooperativeLevel(Window, DISCL_NONEXCLUSIVE | DISCL_BACKGROUND);
}
else
{
hr = Device->SetCooperativeLevel(Window, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND);
}
if (FAILED(hr)) if (FAILED(hr))
{ {
Printf(TEXTCOLOR_ORANGE "Setting cooperative level for %s failed.\n", Name.GetChars()); Printf(TEXTCOLOR_ORANGE "Setting cooperative level for %s failed.\n", Name.GetChars());