29#include "../ui/ui_main.h"
30#include "../ui/ui_nodes.h"
31#include "../ui/node/ui_node_abstractoption.h"
33static SDL_Joystick*
stick =
nullptr;
39#if SDL_VERSION_ATLEAST(2,0,0)
40#define SDL_JoystickName SDL_JoystickNameForIndex
78 unsigned int axes = 0;
79 unsigned int hats = 0;
96 int total = SDL_JoystickNumBalls(
stick);
100 for (
int i = 0;
i < total;
i++) {
103 SDL_JoystickGetBall(
stick,
i, &dx, &dy);
107 if (balldx || balldy) {
114 total = SDL_JoystickNumButtons(
stick);
118 for (
int i = 0;
i < total;
i++) {
119 const bool pressed = (SDL_JoystickGetButton(
stick,
i) != 0);
128 total = SDL_JoystickNumHats(
stick);
132 for (
int i = 0;
i < total;
i++)
133 ((Uint8 *)&hats)[
i] = SDL_JoystickGetHat(
stick,
i);
138 for (
int i = 0;
i < 4;
i++) {
139 if (((Uint8 *)&hats)[
i] != ((Uint8 *)&
stick_state.oldhats)[
i]) {
154 case SDL_HAT_RIGHTUP:
158 case SDL_HAT_RIGHTDOWN:
166 case SDL_HAT_LEFTDOWN:
174 switch (((Uint8 *)&hats)[
i]) {
187 case SDL_HAT_RIGHTUP:
191 case SDL_HAT_RIGHTDOWN:
199 case SDL_HAT_LEFTDOWN:
214 total = SDL_JoystickNumAxes(
stick);
217 for (
int i = 0;
i < 2;
i++) {
218 const Sint16 axis = SDL_JoystickGetAxis(
stick,
i);
219 const float velocity = ((float) axis) / 32767.0f;
244 for (
int i = 2;
i < total;
i++) {
245 const Sint16 axis = SDL_JoystickGetAxis(
stick,
i);
246 const float f = ((float) axis) / 32767.0f;
247 if (f < -in_joystickThreshold->value) {
248 axes |= (1 << (
i * 2));
250 axes |= (1 << ((
i * 2) + 1));
258 for (
int i = 2;
i < 16;
i++) {
276 uiNode_t* joystickOptions =
nullptr;
277 const int total = SDL_NumJoysticks();
282 for (
int i = 0;
i < total;
i++)
298 if (
stick !=
nullptr) {
299 Com_Printf(
"... closing already initialized joystick\n");
300 SDL_JoystickClose(
stick);
306 if (!SDL_WasInit(SDL_INIT_JOYSTICK)) {
308 if (SDL_Init(SDL_INIT_JOYSTICK) == -1) {
315 int total = SDL_NumJoysticks();
317 for (
int i = 0;
i < total;
i++)
326 if (
stick ==
nullptr) {
338 SDL_JoystickEventState(SDL_QUERY);
static struct @11 stick_state
static cvar_t * in_joystick
static cvar_t * in_joystickSpeed
static cvar_t * in_joystickNo
void IN_StartupJoystick(void)
Init available joysticks.
void IN_JoystickMove(void)
static const int hat_keys[16]
static SDL_Joystick * stick
static cvar_t * in_joystickThreshold
void IN_JoystickInitMenu(void)
Adds joysticks to the options menu.
static const int joy_keys[16]
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
void Com_Printf(const char *const fmt,...)
cvar_t * Cvar_Set(const char *varName, const char *value,...)
Sets a cvar value.
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
Atomic structure used to define most of the UI.
void UI_RegisterOption(int dataId, uiNode_t *option)
uiNode_t * UI_AddOption(uiNode_t **tree, const char *name, const char *label, const char *value)
Append an option to an option list.