]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host.c
Merge PR 'Fix several long-lasting font rendering problems'
[xonotic/darkplaces.git] / host.c
diff --git a/host.c b/host.c
index 0957102430ff74c1a078b87acd3096b256698222..4d272e365f52aa42352b6a525e6c9d79fb698a40 100644 (file)
--- a/host.c
+++ b/host.c
@@ -133,6 +133,9 @@ void Host_Error (const char *error, ...)
        if (cls.state == ca_dedicated)
                Sys_Error ("Host_Error: %s",hosterrorstring2);  // dedicated servers exit
 
+       // prevent an endless loop if the error was triggered by a command
+       Cbuf_Clear(cmd_local->cbuf);
+
        CL_Disconnect();
        cls.demonum = -1;
 
@@ -156,7 +159,7 @@ static void Host_Quit_f(cmd_state_t *cmd)
 
 static void Host_Version_f(cmd_state_t *cmd)
 {
-       Con_Printf("Version: %s build %s\n", gamename, buildstring);
+       Con_Printf("Version: %s\n", engineversion);
 }
 
 static void Host_Framerate_c(cvar_t *var)
@@ -199,9 +202,11 @@ void Host_SaveConfig(const char *file)
                f = FS_OpenRealFile(file, "wb", false);
                if (!f)
                {
-                       Con_Printf(CON_ERROR "Couldn't write %s.\n", file);
+                       Con_Printf(CON_ERROR "Couldn't write %s\n", file);
                        return;
                }
+               else
+                       Con_Printf("Saving config to %s ...\n", file);
 
                Key_WriteBindings (f);
                Cvar_WriteVariables (&cvars_all, f);
@@ -214,10 +219,8 @@ static void Host_SaveConfig_f(cmd_state_t *cmd)
 {
        const char *file = CONFIGFILENAME;
 
-       if(Cmd_Argc(cmd) >= 2) {
+       if(Cmd_Argc(cmd) >= 2)
                file = Cmd_Argv(cmd, 1);
-               Con_Printf("Saving to %s\n", file);
-       }
 
        Host_SaveConfig(file);
 }
@@ -365,9 +368,12 @@ Host_Init
 static void Host_Init (void)
 {
        int i;
-       const char* os;
        char vabuf[1024];
 
+       Sys_SDL_Init();
+
+       Memory_Init();
+
        host.hook.ConnectLocal = NULL;
        host.hook.Disconnect = NULL;
        host.hook.ToggleMenu = NULL;
@@ -433,6 +439,7 @@ static void Host_Init (void)
        Memory_Init_Commands();
 
        // initialize console and logging and its cvars/commands
+       // this enables Con_Printf() messages to be coloured
        Con_Init();
 
        // initialize various cvars that could not be initialized earlier
@@ -441,12 +448,11 @@ static void Host_Init (void)
        Sys_Init_Commands();
        COM_Init_Commands();
 
-       // initialize filesystem (including fs_basedir, fs_gamedir, -game, scr_screenshot_name)
+       // initialize filesystem (including fs_basedir, fs_gamedir, -game, scr_screenshot_name, gamename)
        FS_Init();
 
-       // construct a version string for the corner of the console
-       os = DP_OS_NAME;
-       dpsnprintf (engineversion, sizeof (engineversion), "%s %s %s", gamename, os, buildstring);
+       // ASAP! construct a version string for the corner of the console and for crash messages
+       dpsnprintf (engineversion, sizeof (engineversion), "%s %s%s, buildstring: %s", gamename, DP_OS_NAME, cls.state == ca_dedicated ? " dedicated" : "", buildstring);
        Con_Printf("%s\n", engineversion);
 
        // initialize process nice level
@@ -503,6 +509,7 @@ static void Host_Init (void)
        {
                // put up the loading image so the user doesn't stare at a black screen...
                SCR_BeginLoadingPlaque(true);
+               S_Startup();
 #ifdef CONFIG_MENU
                MR_Init();
 #endif
@@ -574,12 +581,12 @@ void Host_Shutdown(void)
 
        if (isdown)
        {
-               Con_Print("recursive shutdown\n");
+               Con_Print(CON_WARN "recursive shutdown\n");
                return;
        }
        if (setjmp(host.abortframe))
        {
-               Con_Print("aborted the quitting frame?!?\n");
+               Con_Print(CON_WARN "aborted the quitting frame?!?\n");
                return;
        }
        isdown = true;
@@ -607,7 +614,7 @@ void Host_Shutdown(void)
        TaskQueue_Shutdown();
        Thread_Shutdown();
        Cmd_Shutdown();
-       Sys_Shutdown();
+       Sys_SDL_Shutdown();
        Log_Close();
        Crypto_Shutdown();
 
@@ -643,6 +650,9 @@ static double Host_Frame(double time)
        // Run any downloads
        Curl_Frame();
 
+       // get new SDL events and add commands from keybindings to the cbuf
+       Sys_SDL_HandleEvents();
+
        // process console commands
        Cbuf_Frame(host.cbuf);
 
@@ -662,43 +672,6 @@ static double Host_Frame(double time)
                return min(cl_wait, sv_wait); // listen server or singleplayer
 }
 
-static inline double Host_Sleep(double time)
-{
-       double delta, time0;
-
-       // convert to microseconds
-       time *= 1000000.0;
-
-       if (time < 1 || host.restless)
-               return 0; // not sleeping this frame
-
-       if(host_maxwait.value <= 0)
-               time = min(time, 1000000.0);
-       else
-               time = min(time, host_maxwait.value * 1000.0);
-
-       time0 = Sys_DirtyTime();
-       if (sv_checkforpacketsduringsleep.integer && !sys_usenoclockbutbenchmark.integer && !svs.threaded) {
-               NetConn_SleepMicroseconds((int)time);
-               if (cls.state != ca_dedicated)
-                       NetConn_ClientFrame(); // helps server browser get good ping values
-               // TODO can we do the same for ServerFrame? Probably not.
-       }
-       else
-       {
-               if (cls.state != ca_dedicated)
-                       Curl_Select(&time);
-               Sys_Sleep((int)time);
-       }
-
-       delta = Sys_DirtyTime() - time0;
-       if (delta < 0 || delta >= 1800)
-               delta = 0;
-
-//     R_TimeReport("sleep");
-       return delta;
-}
-
 // Cloudwalk: Most overpowered function declaration...
 static inline double Host_UpdateTime (double newtime, double oldtime)
 {
@@ -741,13 +714,12 @@ void Host_Main(void)
 
                host.dirtytime = Sys_DirtyTime();
                host.realtime += time = Host_UpdateTime(host.dirtytime, oldtime);
+               oldtime = host.dirtytime;
 
                sleeptime = Host_Frame(time);
-               oldtime = host.dirtytime;
                ++host.framecount;
-
                sleeptime -= Sys_DirtyTime() - host.dirtytime; // execution time
-               host.sleeptime = Host_Sleep(sleeptime);
+               host.sleeptime = Sys_Sleep(sleeptime);
        }
 
        return;