]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_screen.c
physics: fix and refactor unsticking
[xonotic/darkplaces.git] / cl_screen.c
index 202a520e4423df3bd94ea46cf7899d13e07a0456..191cd70a53a950e36f8deaa91d7494d055faf1c4 100644 (file)
@@ -738,7 +738,9 @@ SCR_DrawConsole
 void SCR_DrawConsole (void)
 {
        // infobar and loading progress are not drawn simultaneously
-       scr_con_margin_bottom = SCR_InfobarHeight() ?: scr_loading * scr_loadingscreen_barheight.integer;
+       scr_con_margin_bottom = SCR_InfobarHeight();
+       if (!scr_con_margin_bottom && scr_loading)
+               scr_con_margin_bottom = scr_loadingscreen_barheight.integer;
        if (key_consoleactive & KEY_CONSOLEACTIVE_FORCED)
        {
                // full screen
@@ -997,17 +999,17 @@ void SCR_ScreenShot_f(cmd_state_t *cmd)
                shotnumber++;
        }
 
-       buffer1 = (unsigned char *)Mem_Alloc(tempmempool, vid.width * vid.height * 4);
-       buffer2 = (unsigned char *)Mem_Alloc(tempmempool, vid.width * vid.height * (scr_screenshot_alpha.integer ? 4 : 3));
+       buffer1 = (unsigned char *)Mem_Alloc(tempmempool, vid.mode.width * vid.mode.height * 4);
+       buffer2 = (unsigned char *)Mem_Alloc(tempmempool, vid.mode.width * vid.mode.height * (scr_screenshot_alpha.integer ? 4 : 3));
 
-       if (SCR_ScreenShot (filename, buffer1, buffer2, 0, 0, vid.width, vid.height, false, false, false, jpeg, png, true, scr_screenshot_alpha.integer != 0))
+       if (SCR_ScreenShot (filename, buffer1, buffer2, 0, 0, vid.mode.width, vid.mode.height, false, false, false, jpeg, png, true, scr_screenshot_alpha.integer != 0))
                Con_Printf("Wrote %s\n", filename);
        else
        {
                Con_Printf(CON_ERROR "Unable to write %s\n", filename);
                if(jpeg || png)
                {
-                       if(SCR_ScreenShot (filename, buffer1, buffer2, 0, 0, vid.width, vid.height, false, false, false, false, false, true, scr_screenshot_alpha.integer != 0))
+                       if(SCR_ScreenShot (filename, buffer1, buffer2, 0, 0, vid.mode.width, vid.mode.height, false, false, false, false, false, true, scr_screenshot_alpha.integer != 0))
                        {
                                dp_strlcpy(filename + strlen(filename) - 3, "tga", 4);
                                Con_Printf("Wrote %s\n", filename);
@@ -1031,14 +1033,14 @@ static void SCR_CaptureVideo_BeginVideo(void)
        // soundrate is figured out on the first SoundFrame
 
        if(width == 0 && height != 0)
-               width = (int) (height * (double)vid.width / ((double)vid.height * vid_pixelheight.value)); // keep aspect
+               width = (int) (height * (double)vid.mode.width / ((double)vid.mode.height * vid_pixelheight.value)); // keep aspect
        if(width != 0 && height == 0)
-               height = (int) (width * ((double)vid.height * vid_pixelheight.value) / (double)vid.width); // keep aspect
+               height = (int) (width * ((double)vid.mode.height * vid_pixelheight.value) / (double)vid.mode.width); // keep aspect
 
-       if(width < 2 || width > vid.width) // can't scale up
-               width = vid.width;
-       if(height < 2 || height > vid.height) // can't scale up
-               height = vid.height;
+       if(width < 2 || width > vid.mode.width) // can't scale up
+               width = vid.mode.width;
+       if(height < 2 || height > vid.mode.height) // can't scale up
+               height = vid.mode.height;
 
        // ensure it's all even; if not, scale down a little
        if(width % 1)
@@ -1058,7 +1060,7 @@ static void SCR_CaptureVideo_BeginVideo(void)
        cls.capturevideo.starttime = cls.capturevideo.lastfpstime = host.realtime;
        cls.capturevideo.soundsampleframe = 0;
        cls.capturevideo.realtime = cl_capturevideo_realtime.integer != 0;
-       cls.capturevideo.screenbuffer = (unsigned char *)Mem_Alloc(tempmempool, vid.width * vid.height * 4);
+       cls.capturevideo.screenbuffer = (unsigned char *)Mem_Alloc(tempmempool, vid.mode.width * vid.mode.height * 4);
        cls.capturevideo.outbuffer = (unsigned char *)Mem_Alloc(tempmempool, width * height * (4+4) + 18);
        dpsnprintf(cls.capturevideo.basename, sizeof(cls.capturevideo.basename), "video/%s%03i", Sys_TimeString(cl_capturevideo_nameformat.string), cl_capturevideo_number.integer);
        Cvar_SetValueQuick(&cl_capturevideo_number, cl_capturevideo_number.integer + 1);
@@ -1217,26 +1219,20 @@ static void SCR_CaptureVideo_VideoFrame(int newframestepframenum)
        CHECKGLERROR
        // speed is critical here, so do saving as directly as possible
 
-       GL_ReadPixelsBGRA(x, y, vid.width, vid.height, cls.capturevideo.screenbuffer);
+       GL_ReadPixelsBGRA(x, y, vid.mode.width, vid.mode.height, cls.capturevideo.screenbuffer);
 
-       SCR_ScaleDownBGRA (cls.capturevideo.screenbuffer, vid.width, vid.height, cls.capturevideo.outbuffer, width, height);
+       SCR_ScaleDownBGRA (cls.capturevideo.screenbuffer, vid.mode.width, vid.mode.height, cls.capturevideo.outbuffer, width, height);
 
        cls.capturevideo.videoframes(newframestepframenum - cls.capturevideo.framestepframe);
        cls.capturevideo.framestepframe = newframestepframenum;
 
-       if(cl_capturevideo_printfps.integer)
+       if(cl_capturevideo_printfps.integer && host.realtime > cls.capturevideo.lastfpstime + 1)
        {
-               char buf[80];
-               double t = host.realtime;
-               if(t > cls.capturevideo.lastfpstime + 1)
-               {
-                       double fps1 = (cls.capturevideo.frame - cls.capturevideo.lastfpsframe) / (t - cls.capturevideo.lastfpstime + 0.0000001);
-                       double fps  = (cls.capturevideo.frame                                ) / (t - cls.capturevideo.starttime   + 0.0000001);
-                       dpsnprintf(buf, sizeof(buf), "capturevideo: (%.1fs) last second %.3ffps, total %.3ffps\n", cls.capturevideo.frame / cls.capturevideo.framerate, fps1, fps);
-                       Sys_Print(buf);
-                       cls.capturevideo.lastfpstime = t;
-                       cls.capturevideo.lastfpsframe = cls.capturevideo.frame;
-               }
+               double fps1 = (cls.capturevideo.frame - cls.capturevideo.lastfpsframe) / (host.realtime - cls.capturevideo.lastfpstime + 0.0000001);
+               double fps  = (cls.capturevideo.frame                                ) / (host.realtime - cls.capturevideo.starttime   + 0.0000001);
+               Sys_Printf("capturevideo: (%.1fs) last second %.3ffps, total %.3ffps\n", cls.capturevideo.frame / cls.capturevideo.framerate, fps1, fps);
+               cls.capturevideo.lastfpstime = host.realtime;
+               cls.capturevideo.lastfpsframe = cls.capturevideo.frame;
        }
 }
 
@@ -1347,7 +1343,7 @@ static void R_Envmap_f(cmd_state_t *cmd)
                Con_Print("envmap: size must be one of 128, 256, 512, or 1024\n");
                return;
        }
-       if (size > vid.width || size > vid.height)
+       if (size > vid.mode.width || size > vid.mode.height)
        {
                Con_Print("envmap: your resolution is not big enough to render that size\n");
                return;
@@ -1387,7 +1383,7 @@ static void R_Envmap_f(cmd_state_t *cmd)
                R_Mesh_Start();
                R_RenderView(rt->fbo, rt->depthtexture, rt->colortexture[0], 0, 0, size, size);
                R_Mesh_Finish();
-               SCR_ScreenShot(filename, buffer1, buffer2, 0, vid.height - (r_refdef.view.y + r_refdef.view.height), size, size, envmapinfo[j].flipx, envmapinfo[j].flipy, envmapinfo[j].flipdiagonaly, false, false, false, false);
+               SCR_ScreenShot(filename, buffer1, buffer2, 0, vid.mode.height - (r_refdef.view.y + r_refdef.view.height), size, size, envmapinfo[j].flipx, envmapinfo[j].flipy, envmapinfo[j].flipdiagonaly, false, false, false, false);
        }
 
        Mem_Free (buffer1);
@@ -1626,44 +1622,44 @@ static void SCR_DrawScreen (void)
 
                if (r_stereo_sidebyside.integer)
                {
-                       r_refdef.view.width = (int)(vid.width * size / 2.5);
-                       r_refdef.view.height = (int)(vid.height * size / 2.5 * (1 - bound(0, r_letterbox.value, 100) / 100));
+                       r_refdef.view.width = (int)(vid.mode.width * size / 2.5);
+                       r_refdef.view.height = (int)(vid.mode.height * size / 2.5 * (1 - bound(0, r_letterbox.value, 100) / 100));
                        r_refdef.view.depth = 1;
-                       r_refdef.view.x = (int)((vid.width - r_refdef.view.width * 2.5) * 0.5);
-                       r_refdef.view.y = (int)((vid.height - r_refdef.view.height)/2);
+                       r_refdef.view.x = (int)((vid.mode.width - r_refdef.view.width * 2.5) * 0.5);
+                       r_refdef.view.y = (int)((vid.mode.height - r_refdef.view.height)/2);
                        r_refdef.view.z = 0;
                        if (r_stereo_side)
                                r_refdef.view.x += (int)(r_refdef.view.width * 1.5);
                }
                else if (r_stereo_horizontal.integer)
                {
-                       r_refdef.view.width = (int)(vid.width * size / 2);
-                       r_refdef.view.height = (int)(vid.height * size * (1 - bound(0, r_letterbox.value, 100) / 100));
+                       r_refdef.view.width = (int)(vid.mode.width * size / 2);
+                       r_refdef.view.height = (int)(vid.mode.height * size * (1 - bound(0, r_letterbox.value, 100) / 100));
                        r_refdef.view.depth = 1;
-                       r_refdef.view.x = (int)((vid.width - r_refdef.view.width * 2.0)/2);
-                       r_refdef.view.y = (int)((vid.height - r_refdef.view.height)/2);
+                       r_refdef.view.x = (int)((vid.mode.width - r_refdef.view.width * 2.0)/2);
+                       r_refdef.view.y = (int)((vid.mode.height - r_refdef.view.height)/2);
                        r_refdef.view.z = 0;
                        if (r_stereo_side)
                                r_refdef.view.x += (int)(r_refdef.view.width);
                }
                else if (r_stereo_vertical.integer)
                {
-                       r_refdef.view.width = (int)(vid.width * size);
-                       r_refdef.view.height = (int)(vid.height * size * (1 - bound(0, r_letterbox.value, 100) / 100) / 2);
+                       r_refdef.view.width = (int)(vid.mode.width * size);
+                       r_refdef.view.height = (int)(vid.mode.height * size * (1 - bound(0, r_letterbox.value, 100) / 100) / 2);
                        r_refdef.view.depth = 1;
-                       r_refdef.view.x = (int)((vid.width - r_refdef.view.width)/2);
-                       r_refdef.view.y = (int)((vid.height - r_refdef.view.height * 2.0)/2);
+                       r_refdef.view.x = (int)((vid.mode.width - r_refdef.view.width)/2);
+                       r_refdef.view.y = (int)((vid.mode.height - r_refdef.view.height * 2.0)/2);
                        r_refdef.view.z = 0;
                        if (r_stereo_side)
                                r_refdef.view.y += (int)(r_refdef.view.height);
                }
                else
                {
-                       r_refdef.view.width = (int)(vid.width * size);
-                       r_refdef.view.height = (int)(vid.height * size * (1 - bound(0, r_letterbox.value, 100) / 100));
+                       r_refdef.view.width = (int)(vid.mode.width * size);
+                       r_refdef.view.height = (int)(vid.mode.height * size * (1 - bound(0, r_letterbox.value, 100) / 100));
                        r_refdef.view.depth = 1;
-                       r_refdef.view.x = (int)((vid.width - r_refdef.view.width)/2);
-                       r_refdef.view.y = (int)((vid.height - r_refdef.view.height)/2);
+                       r_refdef.view.x = (int)((vid.mode.width - r_refdef.view.width)/2);
+                       r_refdef.view.y = (int)((vid.mode.height - r_refdef.view.height)/2);
                        r_refdef.view.z = 0;
                }
 
@@ -1686,7 +1682,7 @@ static void SCR_DrawScreen (void)
 
                // if CSQC is loaded, it is required to provide the CSQC_UpdateView function,
                // and won't render a view if it does not call that.
-               if (cl.csqc_loaded)
+               if (CLVM_prog->loaded && !(CLVM_prog->flag & PRVM_CSQC_SIMPLE))
                        CL_VM_UpdateView(r_stereo_side ? 0.0 : max(0.0, cl.time - cl.oldtime));
                else
                {
@@ -1703,8 +1699,8 @@ static void SCR_DrawScreen (void)
 
        if (!r_stereo_sidebyside.integer && !r_stereo_horizontal.integer && !r_stereo_vertical.integer)
        {
-               r_refdef.view.width = vid.width;
-               r_refdef.view.height = vid.height;
+               r_refdef.view.width = vid.mode.width;
+               r_refdef.view.height = vid.mode.height;
                r_refdef.view.depth = 1;
                r_refdef.view.x = 0;
                r_refdef.view.y = 0;
@@ -1736,9 +1732,9 @@ static void SCR_DrawScreen (void)
                        unsigned char *buffer1;
                        unsigned char *buffer2;
                        dpsnprintf(filename, sizeof(filename), "timedemoscreenshots/%s%06d.tga", cls.demoname, cls.td_frames);
-                       buffer1 = (unsigned char *)Mem_Alloc(tempmempool, vid.width * vid.height * 4);
-                       buffer2 = (unsigned char *)Mem_Alloc(tempmempool, vid.width * vid.height * 3);
-                       SCR_ScreenShot(filename, buffer1, buffer2, 0, 0, vid.width, vid.height, false, false, false, false, false, true, false);
+                       buffer1 = (unsigned char *)Mem_Alloc(tempmempool, vid.mode.width * vid.mode.height * 4);
+                       buffer2 = (unsigned char *)Mem_Alloc(tempmempool, vid.mode.width * vid.mode.height * 3);
+                       SCR_ScreenShot(filename, buffer1, buffer2, 0, 0, vid.mode.width, vid.mode.height, false, false, false, false, false, true, false);
                        Mem_Free(buffer1);
                        Mem_Free(buffer2);
                }
@@ -1761,7 +1757,11 @@ static void SCR_DrawScreen (void)
                SCR_DrawTurtle ();
                SCR_DrawPause ();
                if (!r_letterbox.value)
+               {
                        Sbar_Draw();
+                       if (CLVM_prog->loaded && CLVM_prog->flag & PRVM_CSQC_SIMPLE)
+                               CL_VM_DrawHud(r_stereo_side ? 0.0 : max(0.0, cl.time - cl.oldtime));
+               }
                SHOWLMP_drawall();
                SCR_CheckDrawCenterString();
        }
@@ -1828,11 +1828,11 @@ static void SCR_SetLoadingScreenTexture(void)
 
        SCR_ClearLoadingScreenTexture();
 
-       w = vid.width; h = vid.height;
+       w = vid.mode.width; h = vid.mode.height;
        loadingscreentexture_w = loadingscreentexture_h = 1;
 
        loadingscreentexture = R_LoadTexture2D(r_main_texturepool, "loadingscreentexture", w, h, NULL, TEXTYPE_COLORBUFFER, TEXF_RENDERTARGET | TEXF_FORCENEAREST | TEXF_CLAMP, -1, NULL);
-       R_Mesh_CopyToTexture(loadingscreentexture, 0, 0, 0, 0, vid.width, vid.height);
+       R_Mesh_CopyToTexture(loadingscreentexture, 0, 0, 0, 0, vid.mode.width, vid.mode.height);
 
        loadingscreentexture_vertex3f[2] = loadingscreentexture_vertex3f[5] = loadingscreentexture_vertex3f[8] = loadingscreentexture_vertex3f[11] = 0;
        loadingscreentexture_vertex3f[0] = loadingscreentexture_vertex3f[9] = 0;
@@ -2050,8 +2050,8 @@ static void SCR_DrawLoadingScreen (void)
        // apply scale base
        if(scr_loadingscreen_scale_base.integer)
        {
-               w *= vid_conwidth.integer / (float) vid.width;
-               h *= vid_conheight.integer / (float) vid.height;
+               w *= vid_conwidth.integer / (float) vid.mode.width;
+               h *= vid_conheight.integer / (float) vid.mode.height;
        }
 
        // apply scale limit
@@ -2105,7 +2105,7 @@ qbool R_Stereo_ColorMasking(void)
 
 qbool R_Stereo_Active(void)
 {
-       return (vid.stereobuffer || r_stereo_sidebyside.integer || r_stereo_horizontal.integer || r_stereo_vertical.integer || R_Stereo_ColorMasking());
+       return (vid.mode.stereobuffer || r_stereo_sidebyside.integer || r_stereo_horizontal.integer || r_stereo_vertical.integer || R_Stereo_ColorMasking());
 }
 
 static void SCR_UpdateVars(void)
@@ -2113,7 +2113,7 @@ static void SCR_UpdateVars(void)
        float conwidth = bound(160, vid_conwidth.value, 32768);
        float conheight = bound(90, vid_conheight.value, 24576);
        if (vid_conwidthauto.integer)
-               conwidth = floor(conheight * vid.width / (vid.height * vid_pixelheight.value));
+               conwidth = floor(conheight * vid.mode.width / (vid.mode.height * vid_pixelheight.value));
        if (vid_conwidth.value != conwidth)
                Cvar_SetValueQuick(&vid_conwidth, conwidth);
        if (vid_conheight.value != conheight)
@@ -2301,7 +2301,7 @@ void CL_UpdateScreen(void)
        qglDrawBuffer(GL_BACK);CHECKGLERROR
 #endif
 
-       R_Viewport_InitOrtho(&viewport, &identitymatrix, 0, 0, vid.width, vid.height, 0, 0, vid_conwidth.integer, vid_conheight.integer, -10, 100, NULL);
+       R_Viewport_InitOrtho(&viewport, &identitymatrix, 0, 0, vid.mode.width, vid.mode.height, 0, 0, vid_conwidth.integer, vid_conheight.integer, -10, 100, NULL);
        R_Mesh_SetRenderTargets(0, NULL, NULL, NULL, NULL, NULL);
        R_SetViewport(&viewport);
        GL_ScissorTest(false);
@@ -2333,7 +2333,7 @@ void CL_UpdateScreen(void)
                        r_refdef.view.colormask[2] = 0;
                }
 
-               if (vid.stereobuffer)
+               if (vid.mode.stereobuffer)
                        qglDrawBuffer(GL_BACK_RIGHT);
 
                SCR_DrawScreen();
@@ -2348,7 +2348,7 @@ void CL_UpdateScreen(void)
                        r_refdef.view.colormask[2] = r_stereo_redcyan.integer || r_stereo_redblue.integer;
                }
 
-               if (vid.stereobuffer)
+               if (vid.mode.stereobuffer)
                        qglDrawBuffer(GL_BACK_LEFT);
 
                SCR_DrawScreen();