]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
cleaned up edict clearing when connecting or coming back from a level change, this...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 25 Nov 2005 05:24:25 +0000 (05:24 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 25 Nov 2005 05:24:25 +0000 (05:24 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5830 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
host.c
host_cmd.c
netconn.c
sv_main.c

index 020fea7d65dd8e5547059e795ff463aa008fb691..6357034f79805087567c0fdc7b56b4980597bcb3 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -295,8 +295,9 @@ void CL_EstablishConnection(const char *host)
 
        // stop demo loop in case this fails
        CL_Disconnect();
-       NetConn_ClientFrame();
-       NetConn_ServerFrame();
+
+       // run a network frame
+       //NetConn_ClientFrame();SV_VM_Begin();NetConn_ServerFrame();SV_VM_End();
 
        if (LHNETADDRESS_FromString(&cls.connect_address, host, 26000) && (cls.connect_mysocket = NetConn_ChooseClientSocketForAddress(&cls.connect_address)))
        {
@@ -304,17 +305,14 @@ void CL_EstablishConnection(const char *host)
                cls.connect_remainingtries = 3;
                cls.connect_nextsendtime = 0;
                M_Update_Return_Reason("Trying to connect...");
-               if (sv.active)
-               {
-                       NetConn_ClientFrame();
-                       NetConn_ServerFrame();
-                       NetConn_ClientFrame();
-                       NetConn_ServerFrame();
-                       NetConn_ClientFrame();
-                       NetConn_ServerFrame();
-                       NetConn_ClientFrame();
-                       NetConn_ServerFrame();
-               }
+               // run several network frames to jump into the game quickly
+               //if (sv.active)
+               //{
+               //      NetConn_ClientFrame();SV_VM_Begin();NetConn_ServerFrame();SV_VM_End();
+               //      NetConn_ClientFrame();SV_VM_Begin();NetConn_ServerFrame();SV_VM_End();
+               //      NetConn_ClientFrame();SV_VM_Begin();NetConn_ServerFrame();SV_VM_End();
+               //      NetConn_ClientFrame();SV_VM_Begin();NetConn_ServerFrame();SV_VM_End();
+               //}
        }
        else
        {
diff --git a/host.c b/host.c
index 69d7547f0ff9e0a7e1ba2623466e95d99392b292..27d7453b82dc44ae2e1a03b7404e02ec525fd5e8 100644 (file)
--- a/host.c
+++ b/host.c
@@ -486,8 +486,6 @@ void Host_ShutdownServer(qboolean crash)
        if (!sv.active)
                return;
 
-       SV_VM_Begin();
-
        NetConn_Heartbeat(2);
        NetConn_Heartbeat(2);
 
@@ -500,10 +498,11 @@ void Host_ShutdownServer(qboolean crash)
        if (count)
                Con_Printf("Host_ShutdownServer: NetConn_SendToAll failed for %u clients\n", count);
 
+       SV_VM_Begin();
        for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
-               if (host_client->active) {
+               if (host_client->active)
                        SV_DropClient(crash); // server shutdown
-               }
+       SV_VM_End();
 
        NetConn_CloseServerPorts();
 
@@ -513,8 +512,6 @@ void Host_ShutdownServer(qboolean crash)
 //
        memset(&sv, 0, sizeof(sv));
        memset(svs.clients, 0, svs.maxclients*sizeof(client_t));
-
-       SV_VM_End();
 }
 
 
index 2ad0a7bc51845c0ae25c018328dc6d98639fd959..265c8d8780be0a316e925eb01bea1c75f5f4a983 100644 (file)
@@ -1303,9 +1303,6 @@ void Host_Spawn_f (void)
        }
        else
        {
-               // set up the edict
-               PRVM_ED_ClearEdict(host_client->edict);
-
                //Con_Printf("Host_Spawn_f: host_client->edict->netname = %s, host_client->edict->netname = %s, host_client->name = %s\n", PRVM_GetString(host_client->edict->fields.server->netname), PRVM_GetString(host_client->edict->fields.server->netname), host_client->name);
 
                // copy spawn parms out of the client_t
index e06a61ad01a3d1215cd6835f3da8c9b6e6e289be..df02ca4c7b82e070af155afaefc300baacd3e836 100755 (executable)
--- a/netconn.c
+++ b/netconn.c
@@ -1944,8 +1944,8 @@ int NetConn_SendToAll(sizebuf_t *data, double blocktime)
        do
        {
                count = 0;
-               NetConn_ClientFrame();
-               NetConn_ServerFrame();
+               // run a network frame to check for packets
+               NetConn_ClientFrame();SV_VM_Begin();NetConn_ServerFrame();SV_VM_End();
                for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
                {
                        if (host_client->netconnection)
index 388c0748165343e6622397843a0e722ba13806f6..bb18539c231c804fc6bfe609aede060d15488ee5 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -295,27 +295,6 @@ void SV_SendServerinfo (client_t *client)
        client->weaponmodel[0] = 0;
        client->weaponmodelindex = 0;
 
-       // if client is a botclient coming from a level change, we need to set up
-       // client info that normally requires networking
-       if (!client->netconnection)
-       {
-               // set up the edict
-                PRVM_ED_ClearEdict(client->edict);
-
-               // copy spawn parms out of the client_t
-               for (i=0 ; i< NUM_SPAWN_PARMS ; i++)
-                       (&prog->globals.server->parm1)[i] = host_client->spawn_parms[i];
-
-               // call the spawn function
-               host_client->clientconnectcalled = true;
-               prog->globals.server->time = sv.time;
-               prog->globals.server->self = PRVM_EDICT_TO_PROG(client->edict);
-               PRVM_ExecuteProgram (prog->globals.server->ClientConnect, "QC function ClientConnect is missing");
-               PRVM_ExecuteProgram (prog->globals.server->PutClientInServer, "QC function PutClientInServer is missing");
-               host_client->spawned = true;
-               return;
-       }
-
        // LordHavoc: clear entityframe tracking
        client->latestframenum = 0;
 
@@ -427,6 +406,9 @@ void SV_ConnectClient (int clientnum, netconn_t *netconnection)
                        client->spawn_parms[i] = (&prog->globals.server->parm1)[i];
        }
 
+       // set up the entity for this client (including .colormap, .team, etc)
+       PRVM_ED_ClearEdict(client->edict);
+
        // don't call SendServerinfo for a fresh botclient because its fields have
        // not been set up by the qc yet
        if (client->netconnection)
@@ -1793,10 +1775,6 @@ void SV_SpawnServer (const char *server)
                ent->fields.server = (void *)((unsigned char *)prog->edictsfields + i * prog->edict_size);
        }*/
 
-       // fix up client->edict pointers for returning clients right away...
-       for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
-               host_client->edict = PRVM_EDICT_NUM(i + 1);
-
        sv.datagram.maxsize = sizeof(sv.datagram_buf);
        sv.datagram.cursize = 0;
        sv.datagram.data = sv.datagram_buf;
@@ -1863,6 +1841,17 @@ void SV_SpawnServer (const char *server)
 // serverflags are for cross level information (sigils)
        prog->globals.server->serverflags = svs.serverflags;
 
+       // we need to reset the spawned flag on all connected clients here so that
+       // their thinks don't run during startup (before PutClientInServer)
+       // we also need to set up the client entities now
+       // and we need to set the ->edict pointers to point into the progs edicts
+       for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
+       {
+               host_client->spawned = false;
+               host_client->edict = PRVM_EDICT_NUM(i + 1);
+               PRVM_ED_ClearEdict(host_client->edict);
+       }
+
        // load replacement entity file if found
        entities = NULL;
        if (sv_entpatch.integer)
@@ -1884,11 +1873,6 @@ void SV_SpawnServer (const char *server)
        sv.state = ss_active;
        prog->allowworldwrites = false;
 
-       // we need to reset the spawned flag on all connected clients here so that
-       // their thinks don't run during startup (before PutClientInServer)
-       for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
-               host_client->spawned = false;
-
 // run two frames to allow everything to settle
        for (i = 0;i < 2;i++)
        {
@@ -1902,11 +1886,32 @@ void SV_SpawnServer (const char *server)
        if (sv.protocol == PROTOCOL_QUAKE || sv.protocol == PROTOCOL_QUAKEDP || sv.protocol == PROTOCOL_NEHAHRAMOVIE)
                SV_CreateBaseline ();
 
-// send serverinfo to all connected clients
-       // (note this also handles botclients coming back from a level change)
+// send serverinfo to all connected clients, and set up botclients coming back from a level change
        for (i = 0, host_client = svs.clients;i < svs.maxclients;i++, host_client++)
-               if (host_client->active)
+       {
+               if (!host_client->active)
+                       continue;
+               if (host_client->netconnection)
                        SV_SendServerinfo(host_client);
+               else
+               {
+                       int j;
+                       // if client is a botclient coming from a level change, we need to
+                       // set up client info that normally requires networking
+
+                       // copy spawn parms out of the client_t
+                       for (j=0 ; j< NUM_SPAWN_PARMS ; j++)
+                               (&prog->globals.server->parm1)[j] = host_client->spawn_parms[j];
+
+                       // call the spawn function
+                       host_client->clientconnectcalled = true;
+                       prog->globals.server->time = sv.time;
+                       prog->globals.server->self = PRVM_EDICT_TO_PROG(host_client->edict);
+                       PRVM_ExecuteProgram (prog->globals.server->ClientConnect, "QC function ClientConnect is missing");
+                       PRVM_ExecuteProgram (prog->globals.server->PutClientInServer, "QC function PutClientInServer is missing");
+                       host_client->spawned = true;
+               }
+       }
 
        Con_DPrint("Server spawned.\n");
        NetConn_Heartbeat (2);
@@ -1967,9 +1972,9 @@ void SV_VM_CB_InitEdict(prvm_edict_t *e)
                        val->_float = svs.clients[num].colors;
                // NEXUIZ_PLAYERMODEL and NEXUIZ_PLAYERSKIN
                if( eval_playermodel )
-                       PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_playermodel)->string = PRVM_SetEngineString(svs.clients[num].playermodel);
+                       PRVM_GETEDICTFIELDVALUE(e, eval_playermodel)->string = PRVM_SetEngineString(svs.clients[num].playermodel);
                if( eval_playerskin )
-                       PRVM_GETEDICTFIELDVALUE(host_client->edict, eval_playerskin)->string = PRVM_SetEngineString(svs.clients[num].playerskin);
+                       PRVM_GETEDICTFIELDVALUE(e, eval_playerskin)->string = PRVM_SetEngineString(svs.clients[num].playerskin);
        }
 }