From cb6fec84b098472fb3a132f892de1be0080ad576 Mon Sep 17 00:00:00 2001 From: Albert Zeyer Date: Tue, 12 Jan 2010 02:59:49 +0100 Subject: [PATCH 1/1] option to disable joystick support completly (DISABLE_JOYSTICK) --- src/client/AuxLib.cpp | 2 ++ src/client/CInput.cpp | 26 ++++++++++++++------------ src/client/InputEvents.cpp | 4 ++++ src/main.cpp | 4 ++++ 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/src/client/AuxLib.cpp b/src/client/AuxLib.cpp index 251ead3..438ff4f 100644 --- a/src/client/AuxLib.cpp +++ b/src/client/AuxLib.cpp @@ -149,12 +149,14 @@ int InitializeAuxLib(const std::string& config, int bpp, int vidflags) return false; } +#ifndef DISABLE_JOYSTICK if(bJoystickSupport) { if(SDL_InitSubSystem(SDL_INIT_JOYSTICK) != 0) { warnings << "WARNING: couldn't init joystick subystem: " << SDL_GetError() << endl; bJoystickSupport = false; } } +#endif if(!bDedicated && !SetVideoMode()) return false; diff --git a/src/client/CInput.cpp b/src/client/CInput.cpp index 76b330f..d1e11c6 100644 --- a/src/client/CInput.cpp +++ b/src/client/CInput.cpp @@ -153,14 +153,16 @@ int keys_t::keySymFromName(const std::string & name) -#ifdef DEDICATED_ONLY +#if defined(DEDICATED_ONLY) || defined(DISABLE_JOYSTICK) void updateAxisStates() {} void CInput::InitJoysticksTemp() {} void CInput::UnInitJoysticksTemp() {} #else - + +#define HAVE_JOYSTICK + // Joystick axes // TODO: these are set up according to my joystick, are they general enough? enum { @@ -458,7 +460,7 @@ int CInput::Wait(std::string& strText) } } -#ifndef DEDICATED_ONLY +#ifdef HAVE_JOYSTICK // joystick // TODO: more joysticks for(uint n = 0; n < sizeof(Joysticks) / sizeof(joystick_t); n++) { @@ -494,7 +496,7 @@ int CInput::Setup(const std::string& string) return true; } -#ifndef DEDICATED_ONLY +#ifdef HAVE_JOYSTICK // Check if it's a joystick #1 // TODO: allow more joysticks if(string.substr(0,5) == "joy1_") { @@ -541,7 +543,7 @@ int CInput::Setup(const std::string& string) } } } -#endif // !DEDICATED_ONLY +#endif // HAVE_JOYSTICK // Must be a keyboard character @@ -571,7 +573,7 @@ int CInput::Setup(const std::string& string) // Returns the "force" value for a joystick axis int CInput::getJoystickValue() { -#ifndef DEDICATED_ONLY +#ifdef HAVE_JOYSTICK switch (Type) { case INP_JOYSTICK1: return getJoystickControlValue(Data, Extra, joys[0]); @@ -588,7 +590,7 @@ int CInput::getJoystickValue() // Returns true if this input is a joystick axis bool CInput::isJoystickAxis() { -#ifndef DEDICATED_ONLY +#ifdef HAVE_JOYSTICK if (Type == INP_JOYSTICK1 || Type == INP_JOYSTICK2) return Data != JOY_BUTTON; #endif @@ -599,7 +601,7 @@ bool CInput::isJoystickAxis() // Returns true if this joystick is a throttle bool CInput::isJoystickThrottle() { -#ifndef DEDICATED_ONLY +#ifdef HAVE_JOYSTICK if (Type == INP_JOYSTICK1 || Type == INP_JOYSTICK2) return (Data == JOY_THROTTLE_LEFT) || (Data == JOY_THROTTLE_RIGHT); #endif @@ -627,7 +629,7 @@ bool CInput::isUp() return true; break; -#ifndef DEDICATED_ONLY +#ifdef HAVE_JOYSTICK // Joystick case INP_JOYSTICK1: case INP_JOYSTICK2: @@ -656,7 +658,7 @@ bool CInput::isDown() const return true; break; -#ifndef DEDICATED_ONLY +#ifdef HAVE_JOYSTICK // Joystick case INP_JOYSTICK1: return checkJoystickState(Data, Extra, 0); @@ -694,7 +696,7 @@ int CInput::wasDown() const { counter = nDownOnce; // no other way at the moment break; -#ifndef DEDICATED_ONLY +#ifdef HAVE_JOYSTICK case INP_JOYSTICK1: case INP_JOYSTICK2: counter = nDownOnce; // no other way at the moment @@ -719,7 +721,7 @@ int CInput::wasUp() { counter = 0; // no other way at the moment break; -#ifndef DEDICATED_ONLY +#ifdef HAVE_JOYSTICK case INP_JOYSTICK1: case INP_JOYSTICK2: counter = 0; // no other way at the moment diff --git a/src/client/InputEvents.cpp b/src/client/InputEvents.cpp index b011297..c6fc4a0 100644 --- a/src/client/InputEvents.cpp +++ b/src/client/InputEvents.cpp @@ -522,8 +522,10 @@ bool WaitForNextEvent() { HandleMouseState(); HandleKeyboardState(); #ifndef DEDICATED_ONLY +#ifndef DISABLE_JOYSTICK if(bJoystickSupport) SDL_JoystickUpdate(); #endif +#endif HandleCInputs_UpdateUpForNonKeyboard(); HandleCInputs_UpdateDownOnceForNonKeyboard(); @@ -583,11 +585,13 @@ bool ProcessEvents() HandleMouseState(); HandleKeyboardState(); #ifndef DEDICATED_ONLY +#ifndef DISABLE_JOYSTICK if(bJoystickSupport) { SDL_JoystickUpdate(); updateAxisStates(); } #endif +#endif HandleCInputs_UpdateUpForNonKeyboard(); HandleCInputs_UpdateDownOnceForNonKeyboard(); diff --git a/src/main.cpp b/src/main.cpp index 76e1fa6..95e4e85 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -75,7 +75,11 @@ bool bDedicated = true; bool bJoystickSupport = false; #else //DEDICATED_ONLY bool bDedicated = false; +#ifdef DISABLE_JOYSTICK +bool bJoystickSupport = false; +#else bool bJoystickSupport = true; +#endif #endif //DEDICATED_ONLY bool bRestartGameAfterQuit = false; TStartFunction startFunction = NULL; -- 1.6.3