]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host.c
console: improve default text legibility and background alpha behaviour
[xonotic/darkplaces.git] / host.c
diff --git a/host.c b/host.c
index bb1b83fcf82ea4c87d1cb3dbd401ff07ba8066df..7ce6406d21faeee15b6749d5b9ba9b0431b8d565 100644 (file)
--- a/host.c
+++ b/host.c
@@ -44,7 +44,6 @@ host_static_t host;
 cvar_t host_framerate = {CF_CLIENT | CF_SERVER, "host_framerate","0", "locks frame timing to this value in seconds, 0.05 is 20fps for example, note that this can easily run too fast, use cl_maxfps if you want to limit your framerate instead, or sys_ticrate to limit server speed"};
 // shows time used by certain subsystems
 cvar_t host_speeds = {CF_CLIENT | CF_SERVER, "host_speeds","0", "reports how much time is used in server/graphics/sound"};
-cvar_t host_maxwait = {CF_CLIENT | CF_SERVER, "host_maxwait","1000", "maximum sleep time requested from the operating system in millisecond. Larger sleeps will be done using multiple host_maxwait length sleeps. Lowering this value will increase CPU load, but may help working around problems with accuracy of sleep times."};
 
 cvar_t developer = {CF_CLIENT | CF_SERVER | CF_ARCHIVE, "developer","0", "shows debugging messages and information (recommended for all developers and level designers); the value -1 also suppresses buffering and logging these messages"};
 cvar_t developer_extra = {CF_CLIENT | CF_SERVER, "developer_extra", "0", "prints additional debugging messages, often very verbose!"};
@@ -105,44 +104,33 @@ void Host_Error (const char *error, ...)
        Con_Printf(CON_ERROR "Host_Error: %s\n", hosterrorstring1);
 
        // LadyHavoc: if crashing very early, or currently shutting down, do
-       // Sys_Abort instead
+       // Sys_Error instead
        if (host.framecount < 3 || host.state == host_shutdown)
-               Sys_Abort ("Host_Error during %s: %s", host.framecount < 3 ? "startup" : "shutdown", hosterrorstring1);
+               Sys_Error ("Host_Error during %s: %s", host.framecount < 3 ? "startup" : "shutdown", hosterrorstring1);
 
        if (hosterror)
-               Sys_Abort ("Host_Error: recursively entered (original error was: %s    new error is: %s)", hosterrorstring2, hosterrorstring1);
+               Sys_Error ("Host_Error: recursively entered (original error was: %s    new error is: %s)", hosterrorstring2, hosterrorstring1);
        hosterror = true;
 
        dp_strlcpy(hosterrorstring2, hosterrorstring1, sizeof(hosterrorstring2));
 
        CL_Parse_DumpPacket();
-
        CL_Parse_ErrorCleanUp();
 
-       //PR_Crash();
-
        // print out where the crash happened, if it was caused by QC (and do a cleanup)
-       PRVM_Crash(SVVM_prog);
-       PRVM_Crash(CLVM_prog);
-#ifdef CONFIG_MENU
-       PRVM_Crash(MVM_prog);
-#endif
-
-       Cvar_SetValueQuick(&csqc_progcrc, -1);
-       Cvar_SetValueQuick(&csqc_progsize, -1);
+       PRVM_Crash();
 
        if(host.hook.SV_Shutdown)
                host.hook.SV_Shutdown();
 
        if (cls.state == ca_dedicated)
-               Sys_Abort ("Host_Error: %s",hosterrorstring2);        // dedicated servers exit
+               Sys_Error("Host_Error: %s", hosterrorstring1);        // dedicated servers exit
 
        // prevent an endless loop if the error was triggered by a command
        Cbuf_Clear(cmd_local->cbuf);
 
-       // DP8 TODO: send a disconnect message indicating we errored out, see Sys_Abort() and Sys_HandleCrash()
-       CL_Disconnect();
-       cls.demonum = -1;
+       CL_DisconnectEx(false, "Host_Error: %s", hosterrorstring1);
+       cls.demonum = -1; // stop demo loop
 
        hosterror = false;
 
@@ -245,7 +233,10 @@ static void Host_AddConfigText(cmd_state_t *cmd)
                Cbuf_InsertText(cmd, "alias startmap_sp \"map start\"\nalias startmap_dm \"map start\"\nexec teu.rc\n");
        else
                Cbuf_InsertText(cmd, "alias startmap_sp \"map start\"\nalias startmap_dm \"map start\"\nexec " STARTCONFIGFILENAME "\n");
-       Cbuf_Execute(cmd->cbuf);
+
+       // if quake.rc is missing, use default
+       if (!FS_FileExists(STARTCONFIGFILENAME))
+               Cbuf_InsertText(cmd, "exec default.cfg\nexec " CONFIGFILENAME "\nexec autoexec.cfg\n");
 }
 
 /*
@@ -257,14 +248,18 @@ Resets key bindings and cvars to defaults and then reloads scripts
 */
 static void Host_LoadConfig_f(cmd_state_t *cmd)
 {
-       // reset all cvars, commands and aliases to init values
+#ifdef CONFIG_MENU
+       // Xonotic QC complains/breaks if its cvars are deleted before its m_shutdown() is called
+       if(MR_Shutdown)
+               MR_Shutdown();
+#endif
        Cmd_RestoreInitState();
 #ifdef CONFIG_MENU
-       // prepend a menu restart command to execute after the config
-       Cbuf_InsertText(cmd_local, "\nmenu_restart\n");
+       // Must re-add menu.c commands or load menu.dat before executing quake.rc or handling events
+       MR_Init();
 #endif
-       // reset cvars to their defaults, and then exec startup scripts again
-       Host_AddConfigText(cmd_local);
+       // exec startup scripts again
+       Host_AddConfigText(cmd);
 }
 
 /*
@@ -283,7 +278,6 @@ static void Host_InitLocal (void)
        Cvar_RegisterVariable (&host_framerate);
        Cvar_RegisterCallback (&host_framerate, Host_Framerate_c);
        Cvar_RegisterVariable (&host_speeds);
-       Cvar_RegisterVariable (&host_maxwait);
        Cvar_RegisterVariable (&host_isclient);
 
        Cvar_RegisterVariable (&developer);
@@ -345,7 +339,7 @@ void Host_LockSession(void)
                        }
                        else
                        {
-                               Sys_Abort("session lock %s could not be acquired. Please run with -sessionid and an unique session name.\n", p);
+                               Sys_Error("session lock %s could not be acquired. Please run with -sessionid and an unique session name.\n", p);
                        }
                }
        }
@@ -390,7 +384,7 @@ static void Host_Init (void)
        host.state = host_init;
 
        if (setjmp(host.abortframe)) // Huh?!
-               Sys_Abort("Engine initialization failed. Check the console (if available) for additional information.\n");
+               Sys_Error("Engine initialization failed. Check the console (if available) for additional information.\n");
 
        if (Sys_CheckParm("-profilegameonly"))
                Sys_AllowProfiling(false);
@@ -494,13 +488,7 @@ static void Host_Init (void)
        // here comes the not so critical stuff
 
        Host_AddConfigText(cmd_local);
-
-       // if quake.rc is missing, use default
-       if (!FS_FileExists("quake.rc"))
-       {
-               Cbuf_AddText(cmd_local, "exec default.cfg\nexec " CONFIGFILENAME "\nexec autoexec.cfg\n");
-               Cbuf_Execute(cmd_local->cbuf);
-       }
+       Cbuf_Execute(cmd_local->cbuf); // cannot be in Host_AddConfigText as that would cause Host_LoadConfig_f to loop!
 
        host.state = host_active;
 
@@ -574,25 +562,13 @@ static void Host_Init (void)
 ===============
 Host_Shutdown
 
-FIXME: this is a callback from Sys_Quit().  It would be better
-to run quit through here before the final handoff to the sys code.
+Cleanly shuts down after the main loop exits.
 ===============
 */
-void Host_Shutdown(void)
+static void Host_Shutdown(void)
 {
-       static qbool isdown = false;
-
-       if (isdown)
-       {
-               Con_Print(CON_WARN "recursive shutdown\n");
-               return;
-       }
-       if (setjmp(host.abortframe))
-       {
-               Con_Print(CON_WARN "aborted the quitting frame?!?\n");
-               return;
-       }
-       isdown = true;
+       if (Sys_CheckParm("-profilegameonly"))
+               Sys_AllowProfiling(false);
 
        if(cls.state != ca_dedicated)
                CL_Shutdown();
@@ -706,7 +682,7 @@ void Host_Main(void)
        oldtime = Sys_DirtyTime();
 
        // Main event loop
-       while(host.state != host_shutdown)
+       while(host.state < host_shutdown) // see Sys_HandleCrash() comments
        {
                // Something bad happened, or the server disconnected
                if (setjmp(host.abortframe))
@@ -725,5 +701,5 @@ void Host_Main(void)
                host.sleeptime = Sys_Sleep(sleeptime);
        }
 
-       return;
+       Host_Shutdown();
 }