1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
From cb6fec84b098472fb3a132f892de1be0080ad576 Mon Sep 17 00:00:00 2001
From: Albert Zeyer <albert.zeyer@rwth-aachen.de>
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
|