2016-06-25 23:59:34 +02:00
|
|
|
#ifndef BBGE_JOYSTICK_H
|
|
|
|
#define BBGE_JOYSTICK_H
|
|
|
|
|
2016-10-03 23:01:19 +02:00
|
|
|
#include <string>
|
2016-06-25 23:59:34 +02:00
|
|
|
#include <SDL_joystick.h>
|
|
|
|
|
2016-06-30 02:58:55 +02:00
|
|
|
#ifdef BBGE_BUILD_SDL2
|
|
|
|
#include <SDL_gamecontroller.h>
|
|
|
|
#include <SDL_haptic.h>
|
|
|
|
#endif
|
|
|
|
|
2016-06-25 23:59:34 +02:00
|
|
|
#include "Vector.h"
|
|
|
|
|
2016-07-13 05:00:19 +02:00
|
|
|
const static float JOY_AXIS_THRESHOLD = 0.6f;
|
|
|
|
|
2016-06-25 23:59:34 +02:00
|
|
|
class Joystick
|
|
|
|
{
|
|
|
|
public:
|
2016-07-03 18:07:13 +02:00
|
|
|
static unsigned GetNumJoysticks();
|
|
|
|
|
2016-06-25 23:59:34 +02:00
|
|
|
Joystick();
|
2017-06-25 15:56:45 +02:00
|
|
|
~Joystick();
|
|
|
|
|
2016-07-03 18:07:13 +02:00
|
|
|
bool init(int stick=0);
|
2016-06-25 23:59:34 +02:00
|
|
|
void shutdown();
|
2016-06-30 02:58:55 +02:00
|
|
|
//Ranges from 0 to 1 (full speed).
|
2016-06-25 23:59:34 +02:00
|
|
|
void rumble(float leftMotor, float rightMotor, float time);
|
|
|
|
void update(float dt);
|
|
|
|
|
2020-08-11 12:04:15 +02:00
|
|
|
static void Calibrate(Vector &vec, float dead);
|
2016-06-30 02:58:55 +02:00
|
|
|
int getIndex() const { return stickIndex; }
|
|
|
|
int getInstanceID() const { return instanceID; }
|
2016-07-03 18:07:13 +02:00
|
|
|
inline bool isEnabled() const { return enabled; }
|
2016-07-16 22:08:39 +02:00
|
|
|
inline void setEnabled(bool on) { enabled = on; }
|
2016-06-25 23:59:34 +02:00
|
|
|
|
2020-07-07 16:24:03 +02:00
|
|
|
const char *getAxisName(unsigned axis) const;
|
|
|
|
const char *getButtonName(unsigned btn) const;
|
2016-07-15 03:22:27 +02:00
|
|
|
const char *getName() const;
|
|
|
|
const char *getGUID() const;
|
2016-07-13 05:00:19 +02:00
|
|
|
|
2016-06-25 23:59:34 +02:00
|
|
|
private:
|
2020-08-11 12:04:15 +02:00
|
|
|
float clearRumbleTime;
|
2016-07-03 18:07:13 +02:00
|
|
|
bool enabled;
|
2016-06-30 02:58:55 +02:00
|
|
|
int stickIndex;
|
|
|
|
int instanceID;
|
2016-06-26 00:03:10 +02:00
|
|
|
SDL_Joystick *sdl_joy;
|
2016-07-15 03:22:27 +02:00
|
|
|
std::string name;
|
|
|
|
std::string guid;
|
2016-06-25 23:59:34 +02:00
|
|
|
|
|
|
|
# ifdef BBGE_BUILD_SDL2
|
|
|
|
SDL_GameController *sdl_controller;
|
|
|
|
SDL_Haptic *sdl_haptic;
|
|
|
|
# endif
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|