]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_screen.c
Fix some warnings found by cppcheck
[xonotic/darkplaces.git] / cl_screen.c
index 94d6ed102a740297d74d100495a591d692627dba..01a6fbdd1c27091dd95a747fc04c875abdc608fb 100644 (file)
@@ -265,7 +265,7 @@ static void SCR_DrawNetGraph_DrawGraph (int graphx, int graphy, int graphwidth,
        for (j = 0;j < NETGRAPH_PACKETS;j++)
        {
                graph = netgraph + j;
-               g[j][0] = 1.0f - 0.25f * (realtime - graph->time);
+               g[j][0] = 1.0f - 0.25f * (host.realtime - graph->time);
                g[j][1] = 1.0f;
                g[j][2] = 1.0f;
                g[j][3] = 1.0f;
@@ -285,7 +285,7 @@ static void SCR_DrawNetGraph_DrawGraph (int graphx, int graphy, int graphwidth,
                        g[j][4] = g[j][3] - graph->reliablebytes   * graphscale;
                        g[j][5] = g[j][4] - graph->ackbytes        * graphscale;
                        // count bytes in the last second
-                       if (realtime - graph->time < 1.0f)
+                       if (host.realtime - graph->time < 1.0f)
                                totalbytes += graph->unreliablebytes + graph->reliablebytes + graph->ackbytes;
                }
                if(graph->cleartime >= 0)
@@ -343,7 +343,7 @@ static void SCR_DrawNetGraph (void)
        graphwidth = 120;
        graphheight = 70;
        graphscale = 1.0f / 1500.0f;
-       graphlimit = cl_rate.integer;
+       graphlimit = rate.integer;
 
        netgraphsperrow = (vid_conwidth.integer + separator2) / (graphwidth * 2 + separator1 + separator2);
        netgraphsperrow = max(netgraphsperrow, 1);
@@ -409,7 +409,7 @@ static void SCR_DrawNet (void)
 {
        if (cls.state != ca_connected)
                return;
-       if (realtime - cl.last_received_message < 0.3)
+       if (host.realtime - cl.last_received_message < 0.3)
                return;
        if (cls.demoplayback)
                return;
@@ -511,14 +511,14 @@ static int SCR_DrawQWDownload(int offset)
        if (!cls.qw_downloadname[0])
        {
                cls.qw_downloadspeedrate = 0;
-               cls.qw_downloadspeedtime = realtime;
+               cls.qw_downloadspeedtime = host.realtime;
                cls.qw_downloadspeedcount = 0;
                return 0;
        }
-       if (realtime >= cls.qw_downloadspeedtime + 1)
+       if (host.realtime >= cls.qw_downloadspeedtime + 1)
        {
                cls.qw_downloadspeedrate = cls.qw_downloadspeedcount;
-               cls.qw_downloadspeedtime = realtime;
+               cls.qw_downloadspeedtime = host.realtime;
                cls.qw_downloadspeedcount = 0;
        }
        if (cls.protocol == PROTOCOL_QUAKEWORLD)
@@ -725,6 +725,8 @@ void SCR_DrawConsole (void)
                con_vislines = 0;
 }
 
+qboolean scr_loading = false;
+
 /*
 ===============
 SCR_BeginLoadingPlaque
@@ -733,13 +735,15 @@ SCR_BeginLoadingPlaque
 */
 void SCR_BeginLoadingPlaque (qboolean startup)
 {
-       // save console log up to this point to log_file if it was set by configs
-       Log_Start();
-
-       Host_StartVideo();
+       scr_loading = true;
        SCR_UpdateLoadingScreen(false, startup);
 }
 
+void SCR_EndLoadingPlaque(void)
+{
+       scr_loading = false;
+}
+
 //=============================================================================
 
 const char *r_stat_name[r_stat_count] =
@@ -980,8 +984,8 @@ static void R_TimeReport_EndFrame(void)
        mleaf_t *viewleaf;
        static double oldtime = 0;
 
-       r_refdef.stats[r_stat_timedelta] = (int)((realtime - oldtime) * 1000000.0);
-       oldtime = realtime;
+       r_refdef.stats[r_stat_timedelta] = (int)((host.realtime - oldtime) * 1000000.0);
+       oldtime = host.realtime;
        r_refdef.stats[r_stat_quality] = (int)(100 * r_refdef.view.quality);
 
        string[0] = 0;
@@ -1364,11 +1368,11 @@ void CL_Screen_Init(void)
        if (COM_CheckParm ("-noconsole"))
                Cvar_SetQuick(&scr_conforcewhiledisconnected, "0");
 
-       Cmd_AddCommand(&cmd_client, "sizeup",SCR_SizeUp_f, "increase view size (increases viewsize cvar)");
-       Cmd_AddCommand(&cmd_client, "sizedown",SCR_SizeDown_f, "decrease view size (decreases viewsize cvar)");
-       Cmd_AddCommand(&cmd_client, "screenshot",SCR_ScreenShot_f, "takes a screenshot of the next rendered frame");
-       Cmd_AddCommand(&cmd_client, "envmap", R_Envmap_f, "render a cubemap (skybox) of the current scene");
-       Cmd_AddCommand(&cmd_client, "infobar", SCR_InfoBar_f, "display a text in the infobar (usage: infobar expiretime string)");
+       Cmd_AddCommand(CMD_CLIENT, "sizeup",SCR_SizeUp_f, "increase view size (increases viewsize cvar)");
+       Cmd_AddCommand(CMD_CLIENT, "sizedown",SCR_SizeDown_f, "decrease view size (decreases viewsize cvar)");
+       Cmd_AddCommand(CMD_CLIENT, "screenshot",SCR_ScreenShot_f, "takes a screenshot of the next rendered frame");
+       Cmd_AddCommand(CMD_CLIENT, "envmap", R_Envmap_f, "render a cubemap (skybox) of the current scene");
+       Cmd_AddCommand(CMD_CLIENT, "infobar", SCR_InfoBar_f, "display a text in the infobar (usage: infobar expiretime string)");
 
 #ifdef CONFIG_VIDEO_CAPTURE
        SCR_CaptureVideo_Ogg_Init();
@@ -1485,7 +1489,7 @@ void SCR_ScreenShot_f(cmd_state_t *cmd)
                Con_Printf("Wrote %s\n", filename);
        else
        {
-               Con_Printf("Unable to write %s\n", filename);
+               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))
@@ -1534,9 +1538,9 @@ static void SCR_CaptureVideo_BeginVideo(void)
        cls.capturevideo.framestep = cl_capturevideo_framestep.integer;
        cls.capturevideo.soundrate = S_GetSoundRate();
        cls.capturevideo.soundchannels = S_GetSoundChannels();
-       cls.capturevideo.startrealtime = realtime;
+       cls.capturevideo.startrealtime = host.realtime;
        cls.capturevideo.frame = cls.capturevideo.lastfpsframe = 0;
-       cls.capturevideo.starttime = cls.capturevideo.lastfpstime = realtime;
+       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);
@@ -1708,7 +1712,7 @@ static void SCR_CaptureVideo_VideoFrame(int newframestepframenum)
        if(cl_capturevideo_printfps.integer)
        {
                char buf[80];
-               double t = realtime;
+               double t = host.realtime;
                if(t > cls.capturevideo.lastfpstime + 1)
                {
                        double fps1 = (cls.capturevideo.frame - cls.capturevideo.lastfpsframe) / (t - cls.capturevideo.lastfpstime + 0.0000001);
@@ -1745,7 +1749,7 @@ static void SCR_CaptureVideo(void)
                if (cls.capturevideo.realtime)
                {
                        // preserve sound sync by duplicating frames when running slow
-                       newframenum = (int)((realtime - cls.capturevideo.startrealtime) * cls.capturevideo.framerate);
+                       newframenum = (int)((host.realtime - cls.capturevideo.startrealtime) * cls.capturevideo.framerate);
                }
                else
                        newframenum = cls.capturevideo.frame + 1;
@@ -1816,6 +1820,11 @@ static void R_Envmap_f(cmd_state_t *cmd)
                return;
        }
 
+       if(cls.state != ca_connected) {
+               Con_Printf("envmap: No map loaded\n");
+               return;
+       }
+
        strlcpy (basename, Cmd_Argv(cmd, 1), sizeof (basename));
        size = atoi(Cmd_Argv(cmd, 2));
        if (size != 128 && size != 256 && size != 512 && size != 1024)
@@ -2063,7 +2072,25 @@ int r_stereo_side;
 extern cvar_t v_isometric;
 extern cvar_t v_isometric_verticalfov;
 
-static void SCR_DrawLoadingScreen(qboolean clear);
+typedef struct loadingscreenstack_s
+{
+       struct loadingscreenstack_s *prev;
+       char msg[MAX_QPATH];
+       float absolute_loading_amount_min; // this corresponds to relative completion 0 of this item
+       float absolute_loading_amount_len; // this corresponds to relative completion 1 of this item
+       float relative_completion; // 0 .. 1
+}
+loadingscreenstack_t;
+static loadingscreenstack_t *loadingscreenstack = NULL;
+static qboolean loadingscreendone = false;
+static qboolean loadingscreencleared = false;
+static float loadingscreenheight = 0;
+rtexture_t *loadingscreentexture = NULL;
+static float loadingscreentexture_vertex3f[12];
+static float loadingscreentexture_texcoord2f[8];
+static int loadingscreenpic_number = 0;
+
+static void SCR_DrawLoadingScreen(void);
 static void SCR_DrawScreen (void)
 {
        Draw_Frame();
@@ -2153,6 +2180,9 @@ static void SCR_DrawScreen (void)
                        CL_VM_UpdateView(r_stereo_side ? 0.0 : max(0.0, cl.time - cl.oldtime));
                else
                {
+                       // Prepare the scene mesh for rendering - this is lightning beams and other effects rendered as normal surfaces
+                       CL_MeshEntities_Scene_FinalizeRenderEntity();
+
                        CL_UpdateEntityShading();
                        R_RenderView(0, NULL, NULL, r_refdef.view.x, r_refdef.view.y, r_refdef.view.width, r_refdef.view.height);
                }
@@ -2162,12 +2192,12 @@ static void SCR_DrawScreen (void)
                // draw the loading screen for a while if we're still connecting and not forcing the console or menu to show up
                char temp[64];
                if (cls.signon > 0)
-                       SCR_PushLoadingScreen(false, va(temp, sizeof(temp), "Connect: Signon stage %i of %i", cls.signon, SIGNONS), 1.0);
+                       SCR_PushLoadingScreen(va(temp, sizeof(temp), "Connect: Signon stage %i of %i", cls.signon, SIGNONS), 1.0);
                else if (cls.connect_remainingtries > 0)
-                       SCR_PushLoadingScreen(false, va(temp, sizeof(temp), "Connect: Trying...  %i", cls.connect_remainingtries), 1.0);
+                       SCR_PushLoadingScreen(va(temp, sizeof(temp), "Connect: Trying...  %i", cls.connect_remainingtries), 1.0);
                else
-                       SCR_PushLoadingScreen(false, va(temp, sizeof(temp), "Connect: Waiting %i seconds for reply", 10 + cls.connect_remainingtries), 1.0);
-               SCR_DrawLoadingScreen(true);
+                       SCR_PushLoadingScreen(va(temp, sizeof(temp), "Connect: Waiting %i seconds for reply", 10 + cls.connect_remainingtries), 1.0);
+               SCR_DrawLoadingScreen();
                SCR_PopLoadingScreen(false);
        }
 
@@ -2218,8 +2248,13 @@ static void SCR_DrawScreen (void)
        }
 
        // draw 2D stuff
+
+       // Don't flicker when starting a local server.
+       if(scr_loading && !loadingscreenstack && ((!cls.signon && !sv.active) || (cls.signon == SIGNONS)))
+               SCR_EndLoadingPlaque();
+
        if(!scr_con_current && !(key_consoleactive & KEY_CONSOLEACTIVE_FORCED))
-               if ((key_dest == key_game || key_dest == key_message) && !r_letterbox.value)
+               if ((key_dest == key_game || key_dest == key_message) && !r_letterbox.value && !scr_loading)
                        Con_DrawNotify ();      // only draw notify in game
 
        if (cls.signon == SIGNONS)
@@ -2234,25 +2269,29 @@ static void SCR_DrawScreen (void)
        }
        SCR_DrawNetGraph ();
 #ifdef CONFIG_MENU
-       MR_Draw();
+       if(!scr_loading)
+               MR_Draw();
 #endif
        CL_DrawVideo();
        R_Shadow_EditLights_DrawSelectedLightProperties();
 
        SCR_DrawConsole();
+       
+       if(!scr_loading) {
+               SCR_DrawBrand();
 
-       SCR_DrawBrand();
-
-       SCR_DrawInfobar();
-
-       SCR_DrawTouchscreenOverlay();
+               SCR_DrawInfobar();
 
+               SCR_DrawTouchscreenOverlay();
+       }
        if (r_timereport_active)
                R_TimeReport("2d");
 
        R_TimeReport_EndFrame();
        R_TimeReport_BeginFrame();
-       Sbar_ShowFPS();
+       
+       if(!scr_loading)
+               Sbar_ShowFPS();
 
        DrawQ_Finish();
 
@@ -2260,24 +2299,6 @@ static void SCR_DrawScreen (void)
        R_RenderTarget_FreeUnused(false);
 }
 
-typedef struct loadingscreenstack_s
-{
-       struct loadingscreenstack_s *prev;
-       char msg[MAX_QPATH];
-       float absolute_loading_amount_min; // this corresponds to relative completion 0 of this item
-       float absolute_loading_amount_len; // this corresponds to relative completion 1 of this item
-       float relative_completion; // 0 .. 1
-}
-loadingscreenstack_t;
-static loadingscreenstack_t *loadingscreenstack = NULL;
-static qboolean loadingscreendone = false;
-static qboolean loadingscreencleared = false;
-static float loadingscreenheight = 0;
-rtexture_t *loadingscreentexture = NULL;
-static float loadingscreentexture_vertex3f[12];
-static float loadingscreentexture_texcoord2f[8];
-static int loadingscreenpic_number = 0;
-
 static void SCR_ClearLoadingScreenTexture(void)
 {
        if(loadingscreentexture)
@@ -2317,7 +2338,7 @@ void SCR_UpdateLoadingScreenIfShown(void)
                SCR_UpdateLoadingScreen(loadingscreencleared, false);
 }
 
-void SCR_PushLoadingScreen (qboolean redraw, const char *msg, float len_in_parent)
+void SCR_PushLoadingScreen (const char *msg, float len_in_parent)
 {
        loadingscreenstack_t *s = (loadingscreenstack_t *) Z_Malloc(sizeof(loadingscreenstack_t));
        s->prev = loadingscreenstack;
@@ -2339,7 +2360,6 @@ void SCR_PushLoadingScreen (qboolean redraw, const char *msg, float len_in_paren
                s->absolute_loading_amount_len = 1;
        }
 
-       if(redraw)
                SCR_UpdateLoadingScreenIfShown();
 }
 
@@ -2524,7 +2544,7 @@ static void SCR_DrawLoadingScreen_SharedSetup (qboolean clear)
        loadingscreenpic_texcoord2f[6] = 0;loadingscreenpic_texcoord2f[7] = 1;
 }
 
-static void SCR_DrawLoadingScreen (qboolean clear)
+static void SCR_DrawLoadingScreen (void)
 {
        // we only need to draw the image if it isn't already there
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@@ -2545,13 +2565,6 @@ static void SCR_DrawLoadingScreen (qboolean clear)
        SCR_DrawLoadingStack();
 }
 
-static void SCR_DrawLoadingScreen_SharedFinish (qboolean clear)
-{
-       R_Mesh_Finish();
-       // refresh
-       VID_Finish();
-}
-
 static double loadingscreen_lastupdate;
 
 static void SCR_UpdateVars(void);
@@ -2574,10 +2587,7 @@ void SCR_UpdateLoadingScreen (qboolean clear, qboolean startup)
                loadingscreen_lastupdate = t;
        }
 
-       SCR_UpdateVars();
-
        // set up the r_texture_gammaramps texture which we need for rendering the loadingscreenpic
-       VID_UpdateGamma();
        R_UpdateVariables();
 
        if(!scr_loadingscreen_background.integer)
@@ -2615,22 +2625,25 @@ void SCR_UpdateLoadingScreen (qboolean clear, qboolean startup)
        SCR_DrawLoadingScreen_SharedSetup(clear);
        SCR_DrawLoadingScreen(clear);
 #else
-       qglDrawBuffer(GL_BACK);
        SCR_DrawLoadingScreen_SharedSetup(clear);
        if (vid.stereobuffer)
        {
                qglDrawBuffer(GL_BACK_LEFT);
-               SCR_DrawLoadingScreen(clear);
+               SCR_DrawLoadingScreen();
                qglDrawBuffer(GL_BACK_RIGHT);
-               SCR_DrawLoadingScreen(clear);
+               SCR_DrawLoadingScreen();
        }
        else
        {
                qglDrawBuffer(GL_BACK);
-               SCR_DrawLoadingScreen(clear);
+               SCR_DrawLoadingScreen();
        }
 #endif
-       SCR_DrawLoadingScreen_SharedFinish(clear);
+
+       DrawQ_Finish();
+       R_Mesh_Finish();
+       // refresh
+       VID_Finish();
 
        // this goes into the event loop, and should prevent unresponsive cursor on vista
        old_key_dest = key_dest;
@@ -2708,7 +2721,11 @@ void CL_UpdateScreen(void)
        if(drawscreenstart)
        {
                drawscreendelta = Sys_DirtyTime() - drawscreenstart;
+#ifdef CONFIG_VIDEO_CAPTURE
                if (cl_minfps.value > 0 && (cl_minfps_force.integer || !(cls.timedemo || (cls.capturevideo.active && !cls.capturevideo.realtime))) && drawscreendelta >= 0 && drawscreendelta < 60)
+#else
+               if (cl_minfps.value > 0 && (cl_minfps_force.integer || !cls.timedemo) && drawscreendelta >= 0 && drawscreendelta < 60)
+#endif
                {
                        // quality adjustment according to render time
                        double actualframetime;