diff --git a/Quake/in_sdl.c b/Quake/in_sdl.c index 5595e21a2..07381131e 100644 --- a/Quake/in_sdl.c +++ b/Quake/in_sdl.c @@ -109,8 +109,8 @@ static float gyro_yaw = 0.f, gyro_pitch = 0.f, gyro_raw_mag = 0.f; static float gyro_center_frac = 0.f, gyro_center_amount = 0.f; // used for gyro calibration +#define GYRO_CALIBRATION_SAMPLES 300 static float gyro_accum[3] = {0.f, 0.f, 0.f}; -static unsigned int num_samples = 0; static unsigned int updates_countdown = 0; static qboolean gyro_present = false; @@ -1391,8 +1391,7 @@ void IN_StartGyroCalibration (void) gyro_accum[1] = 0.0; gyro_accum[2] = 0.0; - num_samples = 0; - updates_countdown = 300; + updates_countdown = GYRO_CALIBRATION_SAMPLES; } static qboolean IN_UpdateGyroCalibration (const float newsample[3]) @@ -1403,12 +1402,11 @@ static qboolean IN_UpdateGyroCalibration (const float newsample[3]) gyro_accum[0] += newsample[0]; gyro_accum[1] += newsample[1]; gyro_accum[2] += newsample[2]; - num_samples++; updates_countdown--; if (!updates_countdown) { - const float inverseSamples = 1.f / num_samples; + const float inverseSamples = 1.f / GYRO_CALIBRATION_SAMPLES; Cvar_SetValue("gyro_calibration_x", gyro_accum[0] * inverseSamples); Cvar_SetValue("gyro_calibration_y", gyro_accum[1] * inverseSamples); Cvar_SetValue("gyro_calibration_z", gyro_accum[2] * inverseSamples); @@ -1480,6 +1478,11 @@ qboolean IN_IsCalibratingGyro (void) return updates_countdown != 0; } +float IN_GetGyroCalibrationProgress (void) +{ + return (GYRO_CALIBRATION_SAMPLES - updates_countdown) / (float) GYRO_CALIBRATION_SAMPLES; +} + static float IN_FilterGyroSample (float prev, float cur) { float thresh = DEG2RAD (gyro_noise_thresh.value); diff --git a/Quake/input.h b/Quake/input.h index 98cac319a..e7a2272a4 100644 --- a/Quake/input.h +++ b/Quake/input.h @@ -51,6 +51,7 @@ qboolean IN_HasGyro (void); float IN_GetRawGyroMagnitude (void); void IN_StartGyroCalibration (void); qboolean IN_IsCalibratingGyro (void); +float IN_GetGyroCalibrationProgress (void); float IN_GetRawLookMagnitude (void); float IN_GetRawMoveMagnitude (void); diff --git a/Quake/menu.c b/Quake/menu.c index 9e8264bfa..6e0e8505c 100644 --- a/Quake/menu.c +++ b/Quake/menu.c @@ -3102,6 +3102,8 @@ void M_Menu_Calibration_f (void) void M_Calibration_Draw (void) { + char anim[16]; + int i, progress; int y = 72; switch (calibration_state) @@ -3117,7 +3119,12 @@ void M_Calibration_Draw (void) break; case CALIBRATION_IN_ROGRESS: + progress = IN_GetGyroCalibrationProgress () * (Q_COUNTOF (anim) - 1); + for (i = 0; i < (int) Q_COUNTOF (anim) - 1; i++) + anim[i] = i < progress ? '.'|0x80 : '.'; + anim[i] = '\0'; M_PrintAligned (160, y, ALIGN_CENTER, "Calibrating, please wait..."); + M_PrintAligned (160, y + 16, ALIGN_CENTER, anim); if (!IN_IsCalibratingGyro ()) calibration_state = CALIBRATION_FINISHED; break;