]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - host.c
changed cl_brushmodel_entities array from entity_render_t * to int, to fix a crash...
[xonotic/darkplaces.git] / host.c
diff --git a/host.c b/host.c
index c1aeccfd10d42fbe83586d1b9c887dc54f532812..46ca83d03441b4895cb29a9b294c3dc52f1164a1 100644 (file)
--- a/host.c
+++ b/host.c
@@ -152,8 +152,6 @@ void Host_Error (const char *error, ...)
        longjmp (host_abortserver, 1);
 }
 
-mempool_t *sv_clients_mempool = NULL;
-
 void Host_ServerOptions (void)
 {
        int i, numplayers;
@@ -216,8 +214,7 @@ void Host_ServerOptions (void)
                Cvar_SetValueQuick(&deathmatch, 1);
 
        svs.maxclients = numplayers;
-       sv_clients_mempool = Mem_AllocPool("server clients", 0, NULL);
-       svs.clients = Mem_Alloc(sv_clients_mempool, sizeof(client_t) * svs.maxclients);
+       svs.clients = Mem_Alloc(sv_mempool, sizeof(client_t) * svs.maxclients);
 }
 
 /*
@@ -278,9 +275,10 @@ void Host_SaveConfig_f(void)
 
 // dedicated servers initialize the host but don't parse and set the
 // config.cfg cvars
-       if (host_initialized && cls.state != ca_dedicated)
+       // LordHavoc: save a config only after Host_Frame finished the first frame
+       if (host_initialized && host_loopactive && cls.state != ca_dedicated)
        {
-               f = FS_Open ("config.cfg", "wb", false);
+               f = FS_Open ("config.cfg", "wb", false, false);
                if (!f)
                {
                        Con_Print("Couldn't write config.cfg.\n");
@@ -669,30 +667,28 @@ void Host_ServerFrame (void)
 {
        // never run more than 5 frames at a time as a sanity limit
        int framecount, framelimit = 5;
-       double advancetime, newtime;
+       double advancetime;
        if (!sv.active)
+       {
+               sv.timer = 0;
                return;
-       newtime = Sys_DoubleTime();
-       // if this is the first frame of a new server, ignore the huge time difference
-       if (!sv.timer)
-               sv.timer = newtime;
-       // if we're already past the new time, don't run a frame
-       // (does not happen if cl.islocalgame)
-       if (sv.timer > newtime)
-               return;
+       }
+       sv.timer += host_realframetime;
        // run the world state
        // don't allow simulation to run too fast or too slow or logic glitches can occur
-       for (framecount = 0;framecount < framelimit && sv.timer < newtime;framecount++)
+       for (framecount = 0;framecount < framelimit && sv.timer > 0;framecount++)
        {
                if (cl.islocalgame)
-                       advancetime = min(newtime - sv.timer, sys_ticrate.value);
+                       advancetime = min(sv.timer, sys_ticrate.value);
                else
                        advancetime = sys_ticrate.value;
-               sv.timer += advancetime;
+               sv.timer -= advancetime;
 
                // only advance time if not paused
                // the game also pauses in singleplayer when menu or console is used
                sv.frametime = advancetime * slowmo.value;
+               if (host_framerate.value)
+                       sv.frametime = host_framerate.value;
                if (sv.paused || (cl.islocalgame && (key_dest != key_game || key_consoleactive)))
                        sv.frametime = 0;
 
@@ -719,8 +715,8 @@ void Host_ServerFrame (void)
                NetConn_Heartbeat(0);
        }
        // if we fell behind too many frames just don't worry about it
-       if (sv.timer < newtime)
-               sv.timer = newtime;
+       if (sv.timer > 0)
+               sv.timer = 0;
 }
 
 
@@ -812,7 +808,7 @@ void _Host_Frame (float time)
                time2 = Sys_DoubleTime();
 
        // update audio
-       if (cls.signon == SIGNONS && cl.viewentity >= 0 && cl.viewentity < MAX_EDICTS && cl_entities[cl.viewentity].state_current.active)
+       if (cls.signon == SIGNONS && cl_entities[cl.viewentity].state_current.active)
        {
                // LordHavoc: this used to use renderer variables (eww)
                S_Update(&cl_entities[cl.viewentity].render.matrix);
@@ -900,18 +896,18 @@ void Host_Init (void)
 
        Cmd_Init();
        Memory_Init_Commands();
-       R_Modules_Init();
+       Con_Init();
        Cbuf_Init();
+       R_Modules_Init();
        V_Init();
        COM_Init();
-       Host_InitLocal();
        Key_Init();
-       Con_Init();
        PR_Init();
        PRVM_Init();
        Mod_Init();
        NetConn_Init();
        SV_Init();
+       Host_InitLocal();
 
        Con_Printf("Builddate: %s\n", buildstring);
 
@@ -942,6 +938,7 @@ void Host_Init (void)
        if (cls.state != ca_dedicated)
        {
                VID_Open();
+               CDAudio_Startup();
                CL_InitTEnts ();  // We must wait after sound startup to load tent sounds
                SCR_BeginLoadingPlaque();
                MR_Init();