Skip to content

Commit

Permalink
Hide gyro options if not supported
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-drexler committed Dec 29, 2023
1 parent 55d5cfb commit aae8fe2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Quake/in_sdl.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ static float gyro_accum[3];
static unsigned int num_samples;
static unsigned int updates_countdown = 0;

static qboolean gyro_present = false;
static qboolean gyro_active = false;

static int SDLCALL IN_FilterMouseEvents (const SDL_Event *event)
Expand Down Expand Up @@ -326,6 +327,7 @@ void IN_StartupJoystick (void)
if (SDL_GameControllerHasSensor(joy_active_controller, SDL_SENSOR_GYRO)
&& !SDL_GameControllerSetSensorEnabled(joy_active_controller, SDL_SENSOR_GYRO, SDL_TRUE))
{
gyro_present = true;
#if SDL_VERSION_ATLEAST(2, 0, 16)
Con_Printf("Gyro sensor enabled at %.2f Hz\n", SDL_GameControllerGetSensorDataRate(joy_active_controller, SDL_SENSOR_GYRO));
#else
Expand All @@ -334,6 +336,7 @@ void IN_StartupJoystick (void)
}
else
{
gyro_present = false;
Con_Printf("Gyro sensor not found\n");
}
break;
Expand Down Expand Up @@ -1090,6 +1093,11 @@ static void IN_UpdateGyroCalibration (void)
}
}

qboolean IN_HasGyro (void)
{
return gyro_present;
}

qboolean IN_IsCalibratingGyro (void)
{
return updates_countdown != 0;
Expand Down
2 changes: 2 additions & 0 deletions Quake/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ void IN_Commands (void);
// mouse moved by dx and dy pixels
void IN_MouseMotion(int dx, int dy);

// controller gyro
qboolean IN_HasGyro (void);
void IN_StartGyroCalibration (void);
qboolean IN_IsCalibratingGyro (void);

Expand Down
3 changes: 3 additions & 0 deletions Quake/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -3285,6 +3285,7 @@ enum
VIDEO_OPTIONS_ITEMS = VIDEO_OPTIONS_LIST (COUNT_OPTION),
GPAD_OPTIONS_FIRST = OPTIONS_ITEMS + VIDEO_OPTIONS_ITEMS,
GPAD_OPTIONS_ITEMS = GPAD_OPTIONS_LIST (COUNT_OPTION),
GPAD_OPTIONS_GYROITEMS = GPAD_OPTIONS_FIRST + GPAD_OPTIONS_ITEMS - GPAD_OPT_GYROMODE,
#undef COUNT_OPTION
};

Expand Down Expand Up @@ -3425,6 +3426,8 @@ void M_Options_Init (enum m_state_e state)
{
optionsmenu.first_item = GPAD_OPTIONS_FIRST;
optionsmenu.list.numitems = GPAD_OPTIONS_ITEMS;
if (!IN_HasGyro ())
optionsmenu.list.numitems -= GPAD_OPTIONS_GYROITEMS;
optionsmenu.last_cursor = &optionsmenu.gamepad_cursor;
optionsmenu.subtitle = "Gamepad Options";
}
Expand Down

0 comments on commit aae8fe2

Please sign in to comment.