diff --git a/Quake/in_sdl.c b/Quake/in_sdl.c index dd293d6a5..ac70faa93 100644 --- a/Quake/in_sdl.c +++ b/Quake/in_sdl.c @@ -99,8 +99,6 @@ static float gyro_accum[3]; static unsigned int num_samples; static unsigned int updates_countdown = 0; -extern void CalibrationFinishedCallback(void); - static qboolean gyro_active = false; static int SDLCALL IN_FilterMouseEvents (const SDL_Event *event) @@ -1058,8 +1056,10 @@ static void IN_DebugKeyEvent(SDL_Event *event) Sys_DoubleTime()); } -void StartCalibration(void) +void IN_StartGyroCalibration (void) { + Con_Printf ("Calibrating, please wait...\n"); + gyro_accum[0] = 0.0; gyro_accum[1] = 0.0; gyro_accum[2] = 0.0; @@ -1068,6 +1068,33 @@ void StartCalibration(void) updates_countdown = 300; } +static void IN_UpdateGyroCalibration (void) +{ + if (!updates_countdown) + return; + + updates_countdown--; + if (!updates_countdown) + { + 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); + Cvar_SetValue("gyro_calibration_z", gyro_accum[2] * inverseSamples); + + Con_Printf("Calibration results:\n X=%f Y=%f Z=%f\n", + gyro_calibration_x.value, + gyro_calibration_y.value, + gyro_calibration_z.value); + + Con_Printf("Calibration finished\n"); + } +} + +qboolean IN_IsCalibratingGyro (void) +{ + return updates_countdown != 0; +} + void IN_SendKeyEvents (void) { SDL_Event event; @@ -1245,22 +1272,6 @@ void IN_SendKeyEvents (void) } } - if (updates_countdown) - { - updates_countdown--; - if (!updates_countdown) - { - 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); - Cvar_SetValue("gyro_calibration_z", gyro_accum[2] * inverseSamples); - - Con_Printf("Calibration results:\n X=%f Y=%f Z=%f\n", - gyro_calibration_x.value, - gyro_calibration_y.value, - gyro_calibration_z.value); - CalibrationFinishedCallback(); - } - } + IN_UpdateGyroCalibration (); } diff --git a/Quake/input.h b/Quake/input.h index 6047a6261..e05b7177f 100644 --- a/Quake/input.h +++ b/Quake/input.h @@ -34,6 +34,9 @@ void IN_Commands (void); // mouse moved by dx and dy pixels void IN_MouseMotion(int dx, int dy); +void IN_StartGyroCalibration (void); +qboolean IN_IsCalibratingGyro (void); + void IN_SendKeyEvents (void); // used as a callback for Sys_SendKeyEvents() by some drivers diff --git a/Quake/menu.c b/Quake/menu.c index 48872f0cc..7eeb47156 100644 --- a/Quake/menu.c +++ b/Quake/menu.c @@ -76,8 +76,6 @@ extern char crosshair_char; extern qboolean quake64; -extern void StartCalibration(void); - enum m_state_e m_state; extern qboolean keydown[256]; int m_mousex, m_mousey; @@ -3074,54 +3072,83 @@ void M_Menu_Video_f (void) //============================================================================= /* CALIBRATION SCREEN */ -qboolean calibrationComplete; -double calibrationCompleteTime; +static enum +{ + CALIBRATION_INTRO_TEXT, + CALIBRATION_IN_ROGRESS, + CALIBRATION_FINISHED, +} calibration_state; + +static double calibration_finished_delay; void M_Menu_Calibration_f (void) { IN_DeactivateForMenu(); m_state = m_calibration; - calibrationComplete = false; - Con_Printf("Calibrating, please wait...\n"); - StartCalibration(); + calibration_state = CALIBRATION_INTRO_TEXT; + calibration_finished_delay = 1.0; } void M_Calibration_Draw (void) { - int x; - x = (320-27*8)/2; - M_DrawTextBox (x, 72, 27, 1); + int y = 72; - if (! calibrationComplete) + switch (calibration_state) { - x += 16; - M_Print (x, 80, "Calibrating, please wait..."); - } - else - { - x += 32; - M_Print (x, 80, "Calibration complete!"); - if ((realtime - calibrationCompleteTime) > 2.0) - m_state = m_gamepad; + case CALIBRATION_INTRO_TEXT: + M_PrintAligned (160, y - 8, ALIGN_CENTER, "Before calibration,"); + M_PrintAligned (160, y, ALIGN_CENTER, "place the controller"); + M_PrintAligned (160, y + 8, ALIGN_CENTER, "on a flat, stable surface"); + y += 24; + M_DrawTextBox (160 - 5*8, y, 8, 1); + M_DrawArrowCursor (160 - 6*8, y + 8); + M_PrintAligned (160, y + 8, ALIGN_CENTER, "Continue"); + break; + + case CALIBRATION_IN_ROGRESS: + M_PrintAligned (160, y, ALIGN_CENTER, "Calibrating, please wait..."); + if (!IN_IsCalibratingGyro ()) + calibration_state = CALIBRATION_FINISHED; + break; + + case CALIBRATION_FINISHED: + M_PrintAligned (160, y, ALIGN_CENTER, "Calibration complete!"); + calibration_finished_delay -= host_rawframetime; + if (calibration_finished_delay < 0.0) + M_Menu_Gamepad_f (); + break; + + default: + break; } } void M_Calibration_Key (int key) { -} + if (calibration_state != CALIBRATION_INTRO_TEXT) + return; -/* -================ -CalibrationFinishedCallback + switch (key) + { + case K_ENTER: + case K_KP_ENTER: + case K_ABUTTON: + case K_MOUSE1: + calibration_state = CALIBRATION_IN_ROGRESS; + M_ThrottledSound ("misc/menu2.wav"); + IN_StartGyroCalibration (); + break; -called from in_sdl once calibration is finished -================ -*/ -void CalibrationFinishedCallback(void) -{ - Con_Printf("Calibration finished\n"); - calibrationComplete = true; - calibrationCompleteTime = realtime; + case K_ESCAPE: + case K_BBUTTON: + case K_MOUSE4: + case K_MOUSE2: + M_Menu_Gamepad_f (); + break; + + default: + break; + } } //============================================================================= @@ -3138,18 +3165,6 @@ void CalibrationFinishedCallback(void) #define MIN_GYRO_SENS 0.1f #define MAX_GYRO_SENS 8.f -/* -================ -GYRO_Menu_Calibration - -starts gyro calibration -================ -*/ -static void GYRO_Menu_Calibration (void) -{ - M_Menu_Calibration_f(); -} - /* ================ M_Menu_Gamepad_f @@ -3720,7 +3735,7 @@ void M_AdjustSliders (int dir) Cvar_SetValueQuick (&gyro_pitchsensitivity, CLAMP (MIN_GYRO_SENS, gyro_pitchsensitivity.value + dir * .1f, MAX_GYRO_SENS)); break; case GPAD_OPT_CALIBRATE: - GYRO_Menu_Calibration (); + M_Menu_Calibration_f (); break; default: