]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - vid_sdl.c
cl_netfps: reduce pings by synchronising when possible, related fixes
[xonotic/darkplaces.git] / vid_sdl.c
index 7b2eb27dc387d848950d006ee9ac5151d21a11e6..88ec122efb485eaabc925f6daa14e2f7db59461f 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -368,7 +368,7 @@ qbool VID_ShowingKeyboard(void)
        return SDL_IsTextInputActive() != 0;
 }
 
-void VID_SetMouse(qbool relative, qbool hidecursor)
+static void VID_SetMouse(qbool relative, qbool hidecursor)
 {
 #ifndef DP_MOBILETOUCH
 #ifdef MACOSX
@@ -1013,6 +1013,8 @@ void IN_Move( void )
                in_windowmouse_y = y;
        }
 
+       //Con_Printf("Mouse position: in_mouse %f %f in_windowmouse %f %f\n", in_mouse_x, in_mouse_y, in_windowmouse_x, in_windowmouse_y);
+
        VID_BuildJoyState(&joystate);
        VID_ApplyJoyState(&joystate);
 }
@@ -1348,8 +1350,10 @@ void Sys_SDL_HandleEvents(void)
                                break;
                }
 
+       vid_activewindow = !vid_hidden && vid_hasfocus;
+
        // enable/disable sound on focus gain/loss
-       if ((!vid_hidden && vid_activewindow) || !snd_mutewhenidle.integer)
+       if (vid_activewindow || !snd_mutewhenidle.integer)
        {
                if (!sound_active)
                {
@@ -1365,6 +1369,13 @@ void Sys_SDL_HandleEvents(void)
                        sound_active = false;
                }
        }
+
+       if (!vid_activewindow || key_consoleactive || scr_loading)
+               VID_SetMouse(false, false);
+       else if (key_dest == key_menu || key_dest == key_menu_grabbed)
+               VID_SetMouse(vid_mouse.integer && !in_client_mouse && !vid_touchscreen.integer, !vid_touchscreen.integer);
+       else
+               VID_SetMouse(vid_mouse.integer && !cl.csqc_wantsmousemove && cl_prydoncursor.integer <= 0 && (!cls.demoplayback || cl_demo_mousegrab.integer) && !vid_touchscreen.integer, !vid_touchscreen.integer);
 }
 
 /////////////////
@@ -1478,8 +1489,16 @@ static void VID_SetVsync_c(cvar_t *var)
                Con_Printf(CON_ERROR "ERROR: can't %s vsync because %s\n", vsyncwanted ? "activate" : "deactivate", SDL_GetError());
 }
 
+static void VID_SetHints_c(cvar_t *var)
+{
+       SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH,     vid_mouse_clickthrough.integer     ? "1" : "0");
+       SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, vid_minimize_on_focus_loss.integer ? "1" : "0");
+}
+
 void VID_Init (void)
 {
+       SDL_version version;
+
 #ifndef __IPHONEOS__
 #ifdef MACOSX
        Cvar_RegisterVariable(&apple_mouse_noaccel);
@@ -1506,11 +1525,19 @@ void VID_Init (void)
        Cvar_RegisterCallback(&vid_resizable,              VID_ChangeDisplay_c);
        Cvar_RegisterCallback(&vid_borderless,             VID_ChangeDisplay_c);
        Cvar_RegisterCallback(&vid_vsync,                  VID_SetVsync_c);
+       Cvar_RegisterCallback(&vid_mouse_clickthrough,     VID_SetHints_c);
+       Cvar_RegisterCallback(&vid_minimize_on_focus_loss, VID_SetHints_c);
 
        if (SDL_Init(SDL_INIT_VIDEO) < 0)
                Sys_Error ("Failed to init SDL video subsystem: %s", SDL_GetError());
        if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) < 0)
                Con_Printf(CON_ERROR "Failed to init SDL joystick subsystem: %s\n", SDL_GetError());
+
+       SDL_GetVersion(&version);
+       Con_Printf("Linked against SDL version %d.%d.%d\n"
+                  "Using SDL library version %d.%d.%d\n",
+                  SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL,
+                  version.major, version.minor, version.patch);
 }
 
 static int vid_sdljoystickindex = -1;
@@ -1576,16 +1603,6 @@ void VID_EnableJoystick(qbool enable)
                Cvar_SetValueQuick(&joy_active, success ? 1 : 0);
 }
 
-static void VID_OutputVersion(void)
-{
-       SDL_version version;
-       SDL_GetVersion(&version);
-       Con_Printf(     "Linked against SDL version %d.%d.%d\n"
-                                       "Using SDL library version %d.%d.%d\n",
-                                       SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL,
-                                       version.major, version.minor, version.patch );
-}
-
 #ifdef WIN32
 static void AdjustWindowBounds(viddef_mode_t *mode, RECT *rect)
 {
@@ -1655,8 +1672,6 @@ static qbool VID_InitModeGL(viddef_mode_t *mode)
        if(vid_resizable.integer)
                windowflags |= SDL_WINDOW_RESIZABLE;
 
-       VID_OutputVersion();
-
 #ifndef USE_GLES2
 // COMMANDLINEOPTION: SDL GL: -gl_driver <drivername> selects a GL driver library, default is whatever SDL recommends, useful only for 3dfxogl.dll/3dfxvgl.dll or fxmesa or similar, if you don't know what this is for, you don't need it
        i = Sys_CheckParm("-gl_driver");
@@ -1707,9 +1722,13 @@ static qbool VID_InitModeGL(viddef_mode_t *mode)
 #endif
        }
 
+       // DPI scaling prevents use of the native resolution, causing blurry rendering
+       // and/or mouse cursor problems, so we need to opt-out.
+#ifdef WIN32
+       SDL_SetHint(SDL_HINT_WINDOWS_DPI_AWARENESS, "1");
+#endif
 
-       if (vid_mouse_clickthrough.integer)
-               SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
+       VID_SetHints_c(NULL);
 
        SDL_GL_SetAttribute (SDL_GL_DOUBLEBUFFER, 1);
        SDL_GL_SetAttribute (SDL_GL_RED_SIZE, 8);
@@ -1755,11 +1774,7 @@ static qbool VID_InitModeGL(viddef_mode_t *mode)
 
        context = SDL_GL_CreateContext(window);
        if (context == NULL)
-       {
-               Con_Printf(CON_ERROR "Failed to initialize OpenGL context: %s\n", SDL_GetError());
-               VID_Shutdown();
-               return false;
-       }
+               Sys_Error("Failed to initialize OpenGL context: %s\n", SDL_GetError());
 
        GL_InitFunctions();
 
@@ -1774,11 +1789,7 @@ static qbool VID_InitModeGL(viddef_mode_t *mode)
                SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY);
                context = SDL_GL_CreateContext(window);
                if (context == NULL)
-               {
-                       Con_Printf(CON_ERROR "Failed to initialize OpenGL context: %s\n", SDL_GetError());
-                       VID_Shutdown();
-                       return false;
-               }
+                       Sys_Error("Failed to initialize OpenGL context: %s\n", SDL_GetError());
        }
 #endif
 
@@ -1837,8 +1848,6 @@ void VID_Shutdown (void)
 
 void VID_Finish (void)
 {
-       vid_activewindow = !vid_hidden && vid_hasfocus;
-
        VID_UpdateGamma();
 
        if (!vid_hidden)