ManaPlus
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes
Joystick Class Reference

#include <joystick.h>

Public Types

enum  { MAX_BUTTONS = 64 }
 
enum  { UP = 1 , DOWN = 2 , LEFT = 4 , RIGHT = 8 }
 

Public Member Functions

 Joystick (const int no)
 
 ~Joystick ()
 
bool open ()
 
void close ()
 
void setNumber (const int n)
 
void logic ()
 
void startCalibration ()
 
void finishCalibration ()
 
bool isCalibrating () const
 
bool buttonPressed (const unsigned char no) const
 
bool isUp () const
 
bool isDown () const
 
bool isLeft () const
 
bool isRight () const
 
int getNumber () const
 
void setUseInactive (const bool b)
 
void update ()
 
KeysVectorgetActionVector (const SDL_Event &event)
 
KeysVectorgetActionVectorByKey (const int i)
 
int getButtonFromEvent (const SDL_Event &event) const
 
bool isActionActive (const InputActionT index) const
 
bool validate () const
 
void handleRepeat (const int time)
 
void resetRepeat (const int key)
 
void reload ()
 

Static Public Member Functions

static void init ()
 
static int getNumberOfJoysticks ()
 
static bool isEnabled ()
 
static void setEnabled (const bool enabled)
 
static void getNames (std::vector< std::string > &names)
 

Protected Member Functions

void doCalibration ()
 

Protected Attributes

unsigned char mDirection
 
bool mActiveButtons [MAX_BUTTONS]
 
SDL_Joystick * mJoystick
 
int mUpTolerance
 
int mDownTolerance
 
int mLeftTolerance
 
int mRightTolerance
 
bool mCalibrating
 
int mNumber
 
bool mCalibrated
 
int mButtonsNumber
 
bool mUseInactive
 
bool mHaveHats
 
KeyToActionMap mKeyToAction
 
KeyToIdMap mKeyToId
 
KeyTimeMap mKeyTimeMap
 

Static Protected Attributes

static bool mEnabled = false
 
static int joystickCount = 0
 

Detailed Description

Definition at line 34 of file joystick.h.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum

Number of buttons we can handle.

Enumerator
MAX_BUTTONS 

Definition at line 40 of file joystick.h.

41  {
42  MAX_BUTTONS = 64
43  };
@ MAX_BUTTONS
Definition: joystick.h:42

◆ anonymous enum

anonymous enum

Directions, to be used as bitmask values.

Enumerator
UP 
DOWN 
LEFT 
RIGHT 

Definition at line 48 of file joystick.h.

49  {
50  UP = 1,
51  DOWN = 2,
52  LEFT = 4,
53  RIGHT = 8
54  };
@ DOWN
Definition: joystick.h:51
@ RIGHT
Definition: joystick.h:53
@ LEFT
Definition: joystick.h:52

Constructor & Destructor Documentation

◆ Joystick()

Joystick::Joystick ( const int  no)
explicit

Constructor, pass the number of the joystick the new object should access.

Definition at line 47 of file joystick.cpp.

47  :
48  mDirection(0),
49  mJoystick(nullptr),
50  mUpTolerance(0),
51  mDownTolerance(0),
52  mLeftTolerance(0),
53  mRightTolerance(0),
54  mCalibrating(false),
56  mCalibrated(false),
58  mUseInactive(false),
59  mHaveHats(false),
60  mKeyToAction(),
61  mKeyToId(),
62  mKeyTimeMap()
63 {
64  for (int i = 0; i < MAX_BUTTONS; i++)
65  mActiveButtons[i] = false;
66 }
SDL_Joystick * mJoystick
Definition: joystick.h:146
int mUpTolerance
Definition: joystick.h:148
int mLeftTolerance
Definition: joystick.h:150
static int joystickCount
Definition: joystick.h:169
int mButtonsNumber
Definition: joystick.h:155
bool mHaveHats
Definition: joystick.h:157
bool mCalibrated
Definition: joystick.h:154
bool mUseInactive
Definition: joystick.h:156
bool mActiveButtons[MAX_BUTTONS]
Definition: joystick.h:144
KeyToIdMap mKeyToId
Definition: joystick.h:161
unsigned char mDirection
Definition: joystick.h:142
int mRightTolerance
Definition: joystick.h:151
KeyToActionMap mKeyToAction
Definition: joystick.h:159
int mNumber
Definition: joystick.h:153
bool mCalibrating
Definition: joystick.h:152
KeyTimeMap mKeyTimeMap
Definition: joystick.h:163
int mDownTolerance
Definition: joystick.h:149

References mActiveButtons, and MAX_BUTTONS.

Referenced by init().

◆ ~Joystick()

Joystick::~Joystick ( )

Definition at line 68 of file joystick.cpp.

69 {
70  close();
71 }
void close()
Definition: joystick.cpp:200

References close().

Member Function Documentation

◆ buttonPressed()

bool Joystick::buttonPressed ( const unsigned char  no) const

Definition at line 347 of file joystick.cpp.

348 {
349  return (mEnabled && no < MAX_BUTTONS) ? mActiveButtons[no] : false;
350 }
static bool mEnabled
Definition: joystick.h:168

References mActiveButtons, MAX_BUTTONS, and mEnabled.

◆ close()

void Joystick::close ( )

Definition at line 200 of file joystick.cpp.

201 {
202  logger->log("close joystick %d", mNumber);
203  if (mJoystick != nullptr)
204  {
205  SDL_JoystickClose(mJoystick);
206  mJoystick = nullptr;
207  }
208 }
void log(const char *const log_text,...)
Definition: logger.cpp:269
Logger * logger
Definition: logger.cpp:89

References Logger::log(), logger, mJoystick, and mNumber.

Referenced by Setup_Joystick::setTempEnabled(), and ~Joystick().

◆ doCalibration()

void Joystick::doCalibration ( )
protected

Definition at line 319 of file joystick.cpp.

320 {
321  // X-Axis
322  int position = SDL_JoystickGetAxis(mJoystick, 0);
323  if (position > mRightTolerance)
324  mRightTolerance = position;
325  else if (position < mLeftTolerance)
326  mLeftTolerance = position;
327 
328  // Y-Axis
329  position = SDL_JoystickGetAxis(mJoystick, 1);
330  if (position > mDownTolerance)
331  mDownTolerance = position;
332  else if (position < mUpTolerance)
333  mUpTolerance = position;
334 }

References mDownTolerance, mJoystick, mLeftTolerance, mRightTolerance, and mUpTolerance.

Referenced by logic().

◆ finishCalibration()

void Joystick::finishCalibration ( )

Definition at line 336 of file joystick.cpp.

337 {
338  mCalibrated = true;
339  mCalibrating = false;
340  config.setValue("joystick" + toString(mNumber) + "calibrated", true);
341  config.setValue("leftTolerance" + toString(mNumber), mLeftTolerance);
342  config.setValue("rightTolerance" + toString(mNumber), mRightTolerance);
343  config.setValue("upTolerance" + toString(mNumber), mUpTolerance);
344  config.setValue("downTolerance" + toString(mNumber), mDownTolerance);
345 }
void setValue(const std::string &key, const std::string &value)
Configuration config
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774

References config, mCalibrated, mCalibrating, mDownTolerance, mLeftTolerance, mNumber, mRightTolerance, mUpTolerance, Configuration::setValue(), and Catch::toString().

Referenced by Setup_Joystick::action().

◆ getActionVector()

KeysVector * Joystick::getActionVector ( const SDL_Event &  event)

Definition at line 365 of file joystick.cpp.

366 {
367  const int i = getButtonFromEvent(event);
368 
369  if (i < 0 || i >= mButtonsNumber)
370  return nullptr;
371 // logger->log("button triggerAction: %d", i);
372  if (mKeyToAction.find(i) != mKeyToAction.end())
373  return &mKeyToAction[i];
374  return nullptr;
375 }
int getButtonFromEvent(const SDL_Event &event) const
Definition: joystick.cpp:387

References getButtonFromEvent(), mButtonsNumber, and mKeyToAction.

Referenced by InputManager::handleEvent().

◆ getActionVectorByKey()

KeysVector * Joystick::getActionVectorByKey ( const int  i)

Definition at line 377 of file joystick.cpp.

378 {
379  if (i < 0 || i >= mButtonsNumber)
380  return nullptr;
381 // logger->log("button triggerAction: %d", i);
382  if (mKeyToAction.find(i) != mKeyToAction.end())
383  return &mKeyToAction[i];
384  return nullptr;
385 }

References mButtonsNumber, and mKeyToAction.

Referenced by handleRepeat().

◆ getButtonFromEvent()

int Joystick::getButtonFromEvent ( const SDL_Event &  event) const

Definition at line 387 of file joystick.cpp.

388 {
389  if (event.jbutton.which != mNumber)
390  return -1;
391  return event.jbutton.button;
392 }

References mNumber.

Referenced by getActionVector(), and InputManager::setNewKey().

◆ getNames()

void Joystick::getNames ( std::vector< std::string > &  names)
static

Definition at line 352 of file joystick.cpp.

353 {
354  names.clear();
355  for (int i = 0; i < joystickCount; i++)
356  names.push_back(SDL_JoystickNameForIndex(i));
357 }
#define SDL_JoystickNameForIndex
Definition: sdlshared.h:61

References joystickCount, and SDL_JoystickNameForIndex.

Referenced by Setup_Joystick::action(), and Setup_Joystick::Setup_Joystick().

◆ getNumber()

int Joystick::getNumber ( ) const
inline

Definition at line 117 of file joystick.h.

118  { return mNumber; }

Referenced by Setup_Joystick::action(), and Setup_Joystick::Setup_Joystick().

◆ getNumberOfJoysticks()

static int Joystick::getNumberOfJoysticks ( )
inlinestatic

Returns the number of available joysticks.

Definition at line 64 of file joystick.h.

65  { return joystickCount; }

◆ handleRepeat()

void Joystick::handleRepeat ( const int  time)

Definition at line 424 of file joystick.cpp.

425 {
426  BLOCK_START("Joystick::handleRepeat")
428  {
429  bool repeat(false);
430  const int key = (*it).first;
431  if (key >= 0 && key < mButtonsNumber)
432  {
433  if (mActiveButtons[key])
434  repeat = true;
435  }
436  if (repeat)
437  {
438  int &keyTime = (*it).second;
439  if (time > keyTime && abs(time - keyTime)
440  > SDL_DEFAULT_REPEAT_DELAY * 10)
441  {
442  keyTime = time;
444  }
445  }
446  }
447  BLOCK_END("Joystick::handleRepeat")
448 }
bool triggerAction(const KeysVector *const ptrs)
KeysVector * getActionVectorByKey(const int i)
Definition: joystick.cpp:377
#define FOR_EACH(type, iter, array)
Definition: foreach.h:25
KeyTimeMap::iterator KeyTimeMapIter
Definition: inputevent.h:47
InputManager inputManager
#define BLOCK_END(name)
Definition: perfomance.h:80
#define BLOCK_START(name)
Definition: perfomance.h:79

References BLOCK_END, BLOCK_START, FOR_EACH, getActionVectorByKey(), inputManager, mActiveButtons, mButtonsNumber, mKeyTimeMap, and InputManager::triggerAction().

Referenced by InputManager::handleRepeat().

◆ init()

void Joystick::init ( )
static

Initializes the joystick subsystem.

Definition at line 73 of file joystick.cpp.

74 {
75  SDL_InitSubSystem(SDL_INIT_JOYSTICK);
76  // +++ possible to use SDL_EventState with different joystick features.
77  SDL_JoystickEventState(SDL_ENABLE);
78  joystickCount = SDL_NumJoysticks();
79  logger->log("%i joysticks/gamepads found", joystickCount);
80  for (int i = 0; i < joystickCount; i++)
81  logger->log("- %s", SDL_JoystickNameForIndex(i));
82 
83  mEnabled = config.getBoolValue("joystickEnabled");
84 
85  if (joystickCount > 0)
86  {
87  joystick = new Joystick(config.getIntValue("selectedJoystick"));
88  if (mEnabled)
89  joystick->open();
90  }
91 }
bool getBoolValue(const std::string &key) const
int getIntValue(const std::string &key) const
bool open()
Definition: joystick.cpp:93
Joystick(const int no)
Definition: joystick.cpp:47
Joystick * joystick
Definition: joystick.cpp:43

References config, Configuration::getBoolValue(), Configuration::getIntValue(), joystick, Joystick(), joystickCount, Logger::log(), logger, mEnabled, open(), and SDL_JoystickNameForIndex.

Referenced by Client::gameInit().

◆ isActionActive()

bool Joystick::isActionActive ( const InputActionT  index) const

Definition at line 394 of file joystick.cpp.

395 {
396  if (!validate())
397  return false;
398 
399  const InputFunction &key = inputManager.getKey(index);
400  for (size_t i = 0; i < inputFunctionSize; i ++)
401  {
402  const InputItem &val = key.values[i];
403  if (val.type != InputType::JOYSTICK)
404  continue;
405  const int value = val.value;
406  if (value >= 0 && value < mButtonsNumber)
407  {
408  if (mActiveButtons[value])
409  return true;
410  }
411  }
412  return false;
413 }
InputFunction & getKey(InputActionT index) A_CONST
bool validate() const
Definition: joystick.cpp:415
const size_t inputFunctionSize
Definition: inputfunction.h:29
@ JOYSTICK
Definition: inputtype.h:40
InputItem values[inputFunctionSize]
Definition: inputfunction.h:35
int value
Definition: inputitem.h:45
InputTypeT type
Definition: inputitem.h:44

References InputManager::getKey(), inputFunctionSize, inputManager, InputType::JOYSTICK, mActiveButtons, mButtonsNumber, InputItem::type, validate(), InputItem::value, and InputFunction::values.

Referenced by InputManager::isActionActive0().

◆ isCalibrating()

bool Joystick::isCalibrating ( ) const
inline

Definition at line 100 of file joystick.h.

101  { return mCalibrating; }

Referenced by Setup_Joystick::action().

◆ isDown()

bool Joystick::isDown ( ) const
inline

Definition at line 108 of file joystick.h.

109  { return mEnabled && ((mDirection & DOWN) != 0); }

References BeingDirection::DOWN.

Referenced by Game::handleMove().

◆ isEnabled()

static bool Joystick::isEnabled ( )
inlinestatic

Definition at line 81 of file joystick.h.

82  { return mEnabled; }

Referenced by Setup_Joystick::apply().

◆ isLeft()

bool Joystick::isLeft ( ) const
inline

Definition at line 111 of file joystick.h.

112  { return mEnabled && ((mDirection & LEFT) != 0); }

References BeingDirection::LEFT.

Referenced by Game::handleMove().

◆ isRight()

bool Joystick::isRight ( ) const
inline

Definition at line 114 of file joystick.h.

115  { return mEnabled && ((mDirection & RIGHT) != 0); }

References BeingDirection::RIGHT.

Referenced by Game::handleMove().

◆ isUp()

bool Joystick::isUp ( ) const
inline

Definition at line 105 of file joystick.h.

106  { return mEnabled && ((mDirection & UP) != 0); }

References BeingDirection::UP.

Referenced by Game::handleMove().

◆ logic()

void Joystick::logic ( )

Updates the direction and button information.

Definition at line 230 of file joystick.cpp.

231 {
232  BLOCK_START("Joystick::logic")
233  // When calibrating, don't bother the outside with our state
234  if (mCalibrating)
235  {
236  doCalibration();
237  BLOCK_END("Joystick::logic")
238  return;
239  }
240 
241  if (!mEnabled || !mCalibrated)
242  {
243  BLOCK_END("Joystick::logic")
244  return;
245  }
246 
247  mDirection = 0;
248 
249  if (mUseInactive ||
250  settings.inputFocused != KeyboardFocus::Unfocused)
251  {
252  // X-Axis
253  int position = SDL_JoystickGetAxis(mJoystick, 0);
254  if (position >= mRightTolerance)
255  mDirection |= RIGHT;
256  else if (position <= mLeftTolerance)
257  mDirection |= LEFT;
258 
259  // Y-Axis
260  position = SDL_JoystickGetAxis(mJoystick, 1);
261  if (position <= mUpTolerance)
262  mDirection |= UP;
263  else if (position >= mDownTolerance)
264  mDirection |= DOWN;
265 
266 #ifdef DEBUG_JOYSTICK
267  if (SDL_JoystickGetAxis(mJoystick, 2))
268  logger->log("axis 2 pos: %d", SDL_JoystickGetAxis(mJoystick, 2));
269  if (SDL_JoystickGetAxis(mJoystick, 3))
270  logger->log("axis 3 pos: %d", SDL_JoystickGetAxis(mJoystick, 3));
271  if (SDL_JoystickGetAxis(mJoystick, 4))
272  logger->log("axis 4 pos: %d", SDL_JoystickGetAxis(mJoystick, 4));
273 #endif // DEBUG_JOYSTICK
274 
275  if ((mDirection == 0U) && mHaveHats)
276  {
277  // reading only hat 0
278  const uint8_t hat = SDL_JoystickGetHat(mJoystick, 0);
279  if ((hat & SDL_HAT_RIGHT) != 0)
280  mDirection |= RIGHT;
281  else if ((hat & SDL_HAT_LEFT) != 0)
282  mDirection |= LEFT;
283  if ((hat & SDL_HAT_UP) != 0)
284  mDirection |= UP;
285  else if ((hat & SDL_HAT_DOWN) != 0)
286  mDirection |= DOWN;
287  }
288 
289  // Buttons
290  for (int i = 0; i < mButtonsNumber; i++)
291  {
292  const bool state = (SDL_JoystickGetButton(mJoystick, i) == 1);
293  mActiveButtons[i] = state;
294  if (!state)
295  resetRepeat(i);
296 #ifdef DEBUG_JOYSTICK
297  if (mActiveButtons[i])
298  logger->log("button: %d", i);
299 #endif // DEBUG_JOYSTICK
300  }
301  }
302  else
303  {
304  for (int i = 0; i < mButtonsNumber; i++)
305  mActiveButtons[i] = false;
306  }
307  BLOCK_END("Joystick::logic")
308 }
void doCalibration()
Definition: joystick.cpp:319
void resetRepeat(const int key)
Definition: joystick.cpp:450
if(!vert) return
bool hat(InputEvent &event)
Definition: chat.cpp:62
Settings settings
Definition: settings.cpp:32

References BLOCK_END, BLOCK_START, doCalibration(), DOWN, Actions::hat(), Settings::inputFocused, LEFT, Logger::log(), logger, mActiveButtons, mButtonsNumber, mCalibrated, mCalibrating, mDirection, mDownTolerance, mEnabled, mHaveHats, mJoystick, mLeftTolerance, mRightTolerance, mUpTolerance, mUseInactive, resetRepeat(), RIGHT, settings, KeyboardFocus::Unfocused, and UP.

Referenced by Game::handleInput().

◆ open()

bool Joystick::open ( )

Definition at line 93 of file joystick.cpp.

94 {
95  if (mNumber >= joystickCount)
96  mNumber = joystickCount - 1;
97  if (mNumber < 0)
98  {
99  logger->log1("error: incorrect joystick selection");
100  return false;
101  }
102  logger->log("open joystick %d", mNumber);
103 
104  mJoystick = SDL_JoystickOpen(mNumber);
105 
106  if (mJoystick == nullptr)
107  {
108  logger->log("Couldn't open joystick: %s", SDL_GetError());
109  return false;
110  }
111 
112  mButtonsNumber = SDL_JoystickNumButtons(mJoystick);
113  logger->log("Joystick: %i ", mNumber);
114 #ifdef USE_SDL2
115  logger->log("Name: %s", SDL_JoystickName(mJoystick));
116  SDL_JoystickGUID guid = SDL_JoystickGetGUID(mJoystick);
117  std::string guidStr;
118  for (int f = 0; f < 16; f ++)
119  guidStr.append(strprintf("%02x", CAST_U32(guid.data[f])));
120  logger->log("Guid: %s", guidStr.c_str());
121 #if SDL_VERSION_ATLEAST(2, 0, 6)
122  logger->log("Device id: %u:%u.%u",
123  CAST_U32(SDL_JoystickGetVendor(mJoystick)),
124  CAST_U32(SDL_JoystickGetProduct(mJoystick)),
125  CAST_U32(SDL_JoystickGetProductVersion(mJoystick)));
126 
127  SDL_JoystickType type = SDL_JoystickGetType(mJoystick);
128  std::string typeStr;
129  switch (type)
130  {
131  default:
132  case SDL_JOYSTICK_TYPE_UNKNOWN:
133  typeStr = "unknown";
134  break;
135  case SDL_JOYSTICK_TYPE_GAMECONTROLLER:
136  typeStr = "game controller";
137  break;
138  case SDL_JOYSTICK_TYPE_WHEEL:
139  typeStr = "wheel";
140  break;
141  case SDL_JOYSTICK_TYPE_ARCADE_STICK:
142  typeStr = "arcade stick";
143  break;
144  case SDL_JOYSTICK_TYPE_FLIGHT_STICK:
145  typeStr = "flight stick";
146  break;
147  case SDL_JOYSTICK_TYPE_DANCE_PAD:
148  typeStr = "dance pad";
149  break;
150  case SDL_JOYSTICK_TYPE_GUITAR:
151  typeStr = "guitar";
152  break;
153  case SDL_JOYSTICK_TYPE_DRUM_KIT:
154  typeStr = "drum kit";
155  break;
156  case SDL_JOYSTICK_TYPE_ARCADE_PAD:
157  typeStr = "arcade pad";
158  break;
159  case SDL_JOYSTICK_TYPE_THROTTLE:
160  typeStr = "throttle";
161  break;
162  }
163  logger->log("Type: " + typeStr);
164 #endif // SDL_VERSION_ATLEAST(2, 0, 6)
165  // probably need aslo dump SDL_JoystickCurrentPowerLevel
166 #else // USE_SDL2
167 
168  logger->log("Name: %s", SDL_JoystickName(mNumber));
169 #endif // USE_SDL2
170 
171  logger->log("Axes: %i ", SDL_JoystickNumAxes(mJoystick));
172  logger->log("Balls: %i", SDL_JoystickNumBalls(mJoystick));
173  logger->log("Hats: %i", SDL_JoystickNumHats(mJoystick));
174  logger->log("Buttons: %i", mButtonsNumber);
175 
176  mHaveHats = (SDL_JoystickNumHats(mJoystick) > 0);
177 
180 
181 #ifdef __SWITCH__
182  config.setValue("joystick" + toString(mNumber) + "calibrated", true);
183  config.setValue("leftTolerance" + toString(mNumber), -10000);
184  config.setValue("rightTolerance" + toString(mNumber), 10000);
185  config.setValue("upTolerance" + toString(mNumber), -10000);
186  config.setValue("downTolerance" + toString(mNumber), 10000);
187 #endif
188  mCalibrated = config.getValueBool("joystick"
189  + toString(mNumber) + "calibrated", false);
190 
191  mUpTolerance = config.getIntValue("upTolerance" + toString(mNumber));
192  mDownTolerance = config.getIntValue("downTolerance" + toString(mNumber));
193  mLeftTolerance = config.getIntValue("leftTolerance" + toString(mNumber));
194  mRightTolerance = config.getIntValue("rightTolerance" + toString(mNumber));
195  mUseInactive = config.getBoolValue("useInactiveJoystick");
196 
197  return true;
198 }
#define CAST_U32
Definition: cast.h:31
bool getValueBool(const std::string &key, const bool deflt) const
void log1(const char *const log_text)
Definition: logger.cpp:238
std::string strprintf(const char *const format,...)

References CAST_U32, config, Configuration::getBoolValue(), Configuration::getIntValue(), ConfigurationObject::getValueBool(), joystickCount, Logger::log(), Logger::log1(), logger, MAX_BUTTONS, mButtonsNumber, mCalibrated, mDownTolerance, mHaveHats, mJoystick, mLeftTolerance, mNumber, mRightTolerance, mUpTolerance, mUseInactive, Configuration::setValue(), strprintf(), and Catch::toString().

Referenced by init(), setNumber(), and Setup_Joystick::setTempEnabled().

◆ reload()

void Joystick::reload ( )

Definition at line 210 of file joystick.cpp.

211 {
212  joystickCount = SDL_NumJoysticks();
214 }
void setNumber(const int n)
Definition: joystick.cpp:216

References joystickCount, mNumber, and setNumber().

Referenced by Setup_Joystick::action().

◆ resetRepeat()

void Joystick::resetRepeat ( const int  key)

Definition at line 450 of file joystick.cpp.

451 {
452  const KeyTimeMapIter it = mKeyTimeMap.find(key);
453  if (it != mKeyTimeMap.end())
454  (*it).second = tick_time;
455 }
volatile int tick_time
Definition: timer.cpp:53

References mKeyTimeMap, and tick_time.

Referenced by logic().

◆ setEnabled()

static void Joystick::setEnabled ( const bool  enabled)
inlinestatic

Definition at line 86 of file joystick.h.

87  { mEnabled = enabled; }

Referenced by Setup_Joystick::cancel(), and Setup_Joystick::setTempEnabled().

◆ setNumber()

void Joystick::setNumber ( const int  n)

Definition at line 216 of file joystick.cpp.

217 {
218  if (mJoystick != nullptr)
219  {
220  SDL_JoystickClose(mJoystick);
221  mNumber = n;
222  open();
223  }
224  else
225  {
226  mNumber = n;
227  }
228 }

References mJoystick, mNumber, and open().

Referenced by Setup_Joystick::action(), and reload().

◆ setUseInactive()

void Joystick::setUseInactive ( const bool  b)
inline

Definition at line 120 of file joystick.h.

121  { mUseInactive = b; }

Referenced by Setup_Joystick::apply().

◆ startCalibration()

void Joystick::startCalibration ( )

Definition at line 310 of file joystick.cpp.

311 {
312  mUpTolerance = 0;
313  mDownTolerance = 0;
314  mLeftTolerance = 0;
315  mRightTolerance = 0;
316  mCalibrating = true;
317 }

References mCalibrating, mDownTolerance, mLeftTolerance, mRightTolerance, and mUpTolerance.

Referenced by Setup_Joystick::action().

◆ update()

void Joystick::update ( )

Definition at line 359 of file joystick.cpp.

360 {
363 }
void updateKeyActionMap(KeyToActionMap &actionMap, KeyToIdMap &idMap, KeyTimeMap &keyTimeMap, const InputTypeT type) const

References inputManager, InputType::JOYSTICK, mKeyTimeMap, mKeyToAction, mKeyToId, and InputManager::updateKeyActionMap().

Referenced by Client::gameInit(), initEngines(), and InputManager::update().

◆ validate()

bool Joystick::validate ( ) const

Definition at line 415 of file joystick.cpp.

416 {
417  if (mCalibrating || !mEnabled || !mCalibrated)
418  return false;
419 
420  return mUseInactive ||
422 }
KeyboardFocusT inputFocused
Definition: settings.h:155

References Settings::inputFocused, mCalibrated, mCalibrating, mEnabled, mUseInactive, settings, and KeyboardFocus::Unfocused.

Referenced by InputManager::handleEvent(), and isActionActive().

Field Documentation

◆ joystickCount

int Joystick::joystickCount = 0
staticprotected

Definition at line 169 of file joystick.h.

Referenced by getNames(), init(), open(), and reload().

◆ mActiveButtons

bool Joystick::mActiveButtons[MAX_BUTTONS]
protected

Definition at line 144 of file joystick.h.

Referenced by buttonPressed(), handleRepeat(), isActionActive(), Joystick(), and logic().

◆ mButtonsNumber

int Joystick::mButtonsNumber
protected

◆ mCalibrated

bool Joystick::mCalibrated
protected

Definition at line 154 of file joystick.h.

Referenced by finishCalibration(), logic(), open(), and validate().

◆ mCalibrating

bool Joystick::mCalibrating
protected

Definition at line 152 of file joystick.h.

Referenced by finishCalibration(), logic(), startCalibration(), and validate().

◆ mDirection

unsigned char Joystick::mDirection
protected

Definition at line 142 of file joystick.h.

Referenced by logic().

◆ mDownTolerance

int Joystick::mDownTolerance
protected

Definition at line 149 of file joystick.h.

Referenced by doCalibration(), finishCalibration(), logic(), open(), and startCalibration().

◆ mEnabled

bool Joystick::mEnabled = false
staticprotected

Is joystick support enabled.

Definition at line 168 of file joystick.h.

Referenced by buttonPressed(), init(), logic(), and validate().

◆ mHaveHats

bool Joystick::mHaveHats
protected

Definition at line 157 of file joystick.h.

Referenced by logic(), and open().

◆ mJoystick

SDL_Joystick* Joystick::mJoystick
protected

Definition at line 146 of file joystick.h.

Referenced by close(), doCalibration(), logic(), open(), and setNumber().

◆ mKeyTimeMap

KeyTimeMap Joystick::mKeyTimeMap
protected

Definition at line 163 of file joystick.h.

Referenced by handleRepeat(), resetRepeat(), and update().

◆ mKeyToAction

KeyToActionMap Joystick::mKeyToAction
protected

Definition at line 159 of file joystick.h.

Referenced by getActionVector(), getActionVectorByKey(), and update().

◆ mKeyToId

KeyToIdMap Joystick::mKeyToId
protected

Definition at line 161 of file joystick.h.

Referenced by update().

◆ mLeftTolerance

int Joystick::mLeftTolerance
protected

Definition at line 150 of file joystick.h.

Referenced by doCalibration(), finishCalibration(), logic(), open(), and startCalibration().

◆ mNumber

int Joystick::mNumber
protected

Definition at line 153 of file joystick.h.

Referenced by close(), finishCalibration(), getButtonFromEvent(), open(), reload(), and setNumber().

◆ mRightTolerance

int Joystick::mRightTolerance
protected

Definition at line 151 of file joystick.h.

Referenced by doCalibration(), finishCalibration(), logic(), open(), and startCalibration().

◆ mUpTolerance

int Joystick::mUpTolerance
protected

Definition at line 148 of file joystick.h.

Referenced by doCalibration(), finishCalibration(), logic(), open(), and startCalibration().

◆ mUseInactive

bool Joystick::mUseInactive
protected

Definition at line 156 of file joystick.h.

Referenced by logic(), open(), and validate().


The documentation for this class was generated from the following files: