Skip to content

Commit

Permalink
Merge remote-tracking branch 'yquake2/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
0lvin committed Dec 21, 2024
2 parents 8d03b22 + 7211e06 commit dfd2cb3
Show file tree
Hide file tree
Showing 10 changed files with 177 additions and 115 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ else
SDLCFLAGS := $(shell sdl2-config --cflags)
endif

ifdef NO_SDL_GYRO
SDLCFLAGS += -DNO_SDL_GYRO
endif

# ----------

# Base include path.
Expand Down
11 changes: 5 additions & 6 deletions doc/030_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,18 +39,17 @@ Yamagi Quake II ships with 4 renderers:

## Choosing a Sound System

Yamagi Quake II ships with 2 sound system:
Yamagi Quake II ships with 2 sound systems:

* The **OpenAL** sound system: This is the default and highly
recommended. It provides full surround sound support and even HRTF for
recommended. It provides full surround sound support and HRTF for
headphones. But also the plain stereo playback is much better than in
the original sound system. The setup is done mostly through OpenAL,
have a look at the documentation of your OpenAL library.
* The **SDL** sound system: This is the classic sound system, providing
an experience like the original client. Set `s_openal` to `0` and
execute an `snd_restart` to activate it. The classic sound system may
be somewhat problematic on modern systems like Windows 10 or Linux
with Pulseaudio.
an experience like the original client. It's less CPU demanding than
OpenAL. Choose it in the options menu, or set `s_openal` to `0` and
execute an `snd_restart`, to activate it.


## Tuning for Precise Timings
Expand Down
4 changes: 4 additions & 0 deletions doc/040_cvarlist.md
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,10 @@ it's `+set busywait 0` (setting the `busywait` cvar) and `-portable`
look a bit better (no flickering) by using the stencil buffer. Does
not work when `gl1_stereo` is `3`, `4` or `5`.

* **gl1_waterwarp**: Intensity of the "squeeze/stretch" effect on the
FOV when diving underwater. Can be any floating point number, `0`
disables it (Vanilla Quake II look). Default `1.0`.

* **gl1_lightmapcopies**: When enabled (`1`), keep 3 copies of the same
lightmap rotating, shifting to another one when drawing a new frame.
Meant for mobile/embedded devices, where changing textures just shown
Expand Down
2 changes: 1 addition & 1 deletion src/client/cl_console.c
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,7 @@ Con_DrawConsole(float frac)
sprintf(dlbar + strlen(dlbar), " %02d%%", cls.downloadpercent);

/* draw it */
y = con.vislines - 12;
y = (lines - 12 * scale) / scale;

for (i = 0; i < strlen(dlbar); i++)
{
Expand Down
60 changes: 35 additions & 25 deletions src/client/input/sdl2.c
Original file line number Diff line number Diff line change
Expand Up @@ -173,19 +173,20 @@ static cvar_t *gyro_calibration_x;
static cvar_t *gyro_calibration_y;
static cvar_t *gyro_calibration_z;

#if SDL_VERSION_ATLEAST(2, 0, 14) // support for controller sensors (gyro, accelerometer)
// If the used SDL version doesn't support gamepad sensors...
#if !SDL_VERSION_ATLEAST(2, 0, 14)
// ...disable support for reading them.
#define NO_SDL_GYRO
#endif

#ifndef NO_SDL_GYRO // use SDL_CONTROLLERSENSORUPDATE to read gyro
static unsigned int num_samples;
#define NATIVE_SDL_GYRO // uses SDL_CONTROLLERSENSORUPDATE to read gyro

#else // for SDL < 2.0.14, gyro can be read as a "secondary joystick" exposed by dkms-hid-nintendo

#else // gyro can be read as a "secondary joystick" exposed by dkms-hid-nintendo
static unsigned int num_samples[3];
static SDL_Joystick *imu_joystick = NULL; // gyro "joystick"
#define IMU_JOY_AXIS_GYRO_ROLL 3
#define IMU_JOY_AXIS_GYRO_PITCH 4
#define IMU_JOY_AXIS_GYRO_YAW 5

#endif

// To ignore SDL_JOYDEVICEADDED at game init. Allows for hot plugging of game controller afterwards.
Expand Down Expand Up @@ -789,7 +790,7 @@ IN_Update(void)
break;
}

#ifdef NATIVE_SDL_GYRO // controller sensors' reading supported (gyro, accelerometer)
#ifndef NO_SDL_GYRO // gamepad sensors' reading is supported (gyro, accelerometer)
case SDL_CONTROLLERSENSORUPDATE:
if (event.csensor.sensor != SDL_SENSOR_GYRO)
{
Expand All @@ -804,7 +805,7 @@ IN_Update(void)
break;
}

#else // gyro read as "secondary joystick"
#else // gyro read from a "secondary joystick" (usually with name ending in "IMU")
case SDL_JOYAXISMOTION:
if ( !imu_joystick || event.cdevice.which != SDL_JoystickInstanceID(imu_joystick) )
{
Expand All @@ -831,12 +832,12 @@ IN_Update(void)
break;
}

#endif // NATIVE_SDL_GYRO
#endif // !NO_SDL_GYRO

if (gyro_active && gyro_mode->value &&
!cl_paused->value && cls.key_dest == key_game)
{
#ifdef NATIVE_SDL_GYRO
#ifndef NO_SDL_GYRO
if (!gyro_turning_axis->value)
{
gyro_yaw = event.csensor.data[1] - gyro_calibration_y->value; // yaw
Expand Down Expand Up @@ -864,7 +865,7 @@ IN_Update(void)
gyro_yaw = axis_value - gyro_calibration_z->value;
}
}
#endif // NATIVE_SDL_GYRO
#endif // !NO_SDL_GYRO
}
else
{
Expand Down Expand Up @@ -956,7 +957,7 @@ IN_Update(void)

case REASON_GYROCALIBRATION: // finish and save calibration
{
#ifdef NATIVE_SDL_GYRO
#ifndef NO_SDL_GYRO
const float inverseSamples = 1.f / num_samples;
Cvar_SetValue("gyro_calibration_x", gyro_accum[0] * inverseSamples);
Cvar_SetValue("gyro_calibration_y", gyro_accum[1] * inverseSamples);
Expand Down Expand Up @@ -1081,7 +1082,7 @@ IN_TightenInput(float yaw, float pitch)
{
thumbstick_t input = { yaw, pitch };
const float magnitude = IN_StickMagnitude(input);
#ifdef NATIVE_SDL_GYRO
#ifndef NO_SDL_GYRO
const float threshold = (M_PI / 180.0f) * gyro_tightening->value;
#else
const float threshold = (2560.0f / 180.0f) * gyro_tightening->value;
Expand Down Expand Up @@ -1369,7 +1370,7 @@ IN_Move(usercmd_t *cmd)
//
// For movement this is not needed, as those are absolute values independent of framerate
float joyViewFactor = cls.rframetime/0.01666f;
#ifdef NATIVE_SDL_GYRO
#ifndef NO_SDL_GYRO
float gyroViewFactor = (1.0f / M_PI) * joyViewFactor;
#else
float gyroViewFactor = (1.0f / 2560.0f) * joyViewFactor; // normalized for Switch gyro
Expand Down Expand Up @@ -1929,7 +1930,7 @@ Controller_Rumble(const char *name, vec3_t source, qboolean from_player,
void
StartCalibration(void)
{
#ifdef NATIVE_SDL_GYRO
#ifndef NO_SDL_GYRO
num_samples = 0;
#else
num_samples[0] = num_samples[1] = num_samples[2] = 0;
Expand Down Expand Up @@ -2052,27 +2053,36 @@ IN_Controller_Init(qboolean notify_user)
Com_Printf ("Trying joystick %d, '%s'\n", i+1, joystick_name);

// Ugly hack to detect IMU-only devices - works for Switch controllers at least
if (name_len > 4 && !strncmp(joystick_name + name_len - 4, " IMU", 4))
if ( name_len > 6 && strstr(joystick_name + name_len - 6, "IMU") )
{
#ifndef NO_SDL_GYRO
SDL_JoystickClose(joystick);
joystick = NULL;
#ifdef NATIVE_SDL_GYRO
Com_Printf ("Skipping IMU device.\n");

#else // if it's not a Left JoyCon, use it as Gyro
Com_Printf ("IMU device found.\n");
if ( !imu_joystick && name_len > 16 && strncmp(joystick_name + name_len - 16, "Left Joy-Con IMU", 16) != 0 )
qboolean using_imu = !imu_joystick && !( strstr(joystick_name, "Joy-Con") && strstr(joystick_name, "L") );
Com_Printf ("IMU device found... ");
SDL_JoystickClose(joystick);
joystick = NULL;

if (using_imu)
{
imu_joystick = SDL_JoystickOpen(i);
if (imu_joystick)
{
show_gyro = true;
Com_Printf ("Using this device as Gyro sensor.\n");
Com_Printf ("using it as Gyro sensor.\n");
}
else
{
Com_Printf ("Couldn't open IMU: %s.\n", SDL_GetError());
Com_Printf ("\nCouldn't open IMU: %s.\n", SDL_GetError());
}
}
else
{
Com_Printf ("skipping.\n");
}
#endif
continue;
}
Expand Down Expand Up @@ -2109,7 +2119,7 @@ IN_Controller_Init(qboolean notify_user)
show_gamepad = true;
Com_Printf("Enabled as Game Controller, settings:\n%s\n", SDL_GameControllerMapping(controller));

#ifdef NATIVE_SDL_GYRO
#ifndef NO_SDL_GYRO

if ( SDL_GameControllerHasSensor(controller, SDL_SENSOR_GYRO)
&& !SDL_GameControllerSetSensorEnabled(controller, SDL_SENSOR_GYRO, SDL_TRUE) )
Expand All @@ -2132,7 +2142,7 @@ IN_Controller_Init(qboolean notify_user)
SDL_GameControllerSetLED(controller, 0, 80, 0); // green light
}

#endif // NATIVE_SDL_GYRO
#endif // !NO_SDL_GYRO

joystick_haptic = SDL_HapticOpenFromJoystick(SDL_GameControllerGetJoystick(controller));

Expand Down Expand Up @@ -2166,7 +2176,7 @@ IN_Controller_Init(qboolean notify_user)
Com_Printf("Controller doesn't support rumble.\n");
}

#ifdef NATIVE_SDL_GYRO // "native" exits when finding a single working controller
#ifndef NO_SDL_GYRO // "native SDL gyro" exits when finding a single working gamepad
break;
#endif
}
Expand Down Expand Up @@ -2283,7 +2293,7 @@ IN_Controller_Shutdown(qboolean notify_user)
joystick_left_x = joystick_left_y = joystick_right_x = joystick_right_y = 0;
gyro_yaw = gyro_pitch = 0;

#ifndef NATIVE_SDL_GYRO
#ifdef NO_SDL_GYRO
if (imu_joystick)
{
SDL_JoystickClose(imu_joystick);
Expand Down
Loading

0 comments on commit dfd2cb3

Please sign in to comment.