]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_parse.c
Added the global float "intermission" to CSQC defs (in clprogdefs.h). Intermission...
[xonotic/darkplaces.git] / cl_parse.c
index 4a1dca33433d00b92fa9c9a331eea9907f23a6ed..b304a756c59486dadec924d0ca0d4545bca33e3e 100644 (file)
@@ -262,6 +262,9 @@ void CL_ParseStartSoundPacket(int largesoundindex)
                return;
        }
 
+       if (ent >= cl.max_entities)
+               CL_ExpandEntities(ent);
+
        S_StartSound (ent, channel, cl.sound_precache[sound_num], pos, volume/255.0f, attenuation);
 }
 
@@ -284,7 +287,7 @@ void CL_KeepaliveMessage (qboolean readmessages)
        sizebuf_t old;
 
        // no need if server is local and definitely not if this is a demo
-       if (sv.active || !cls.netcon || cls.protocol == PROTOCOL_QUAKEWORLD)
+       if (!cls.netcon || cls.protocol == PROTOCOL_QUAKEWORLD)
                return;
 
        if (readmessages)
@@ -315,7 +318,7 @@ void CL_KeepaliveMessage (qboolean readmessages)
                msg.data = buf;
                msg.maxsize = sizeof(buf);
                MSG_WriteChar(&msg, clc_nop);
-               NetConn_SendUnreliableMessage(cls.netcon, &msg, cls.protocol, 10000);
+               NetConn_SendUnreliableMessage(cls.netcon, &msg, cls.protocol, 10000, false);
        }
 }
 
@@ -367,6 +370,47 @@ void CL_ParseEntityLump(char *entdata)
        }
 }
 
+extern void CL_Locs_Reload_f(void);
+extern void CL_VM_Init (void);
+static void CL_SetupWorldModel(void)
+{
+       // update the world model
+       cl.entities[0].render.model = cl.worldmodel = cl.model_precache[1];
+       CL_UpdateRenderEntity(&cl.entities[0].render);
+
+       // set up csqc world for collision culling
+       if (cl.worldmodel)
+       {
+               VectorCopy(cl.worldmodel->normalmins, cl.world.areagrid_mins);
+               VectorCopy(cl.worldmodel->normalmaxs, cl.world.areagrid_maxs);
+       }
+       else
+       {
+               VectorSet(cl.world.areagrid_mins, -4096, -4096, -4096);
+               VectorSet(cl.world.areagrid_maxs, 4096, 4096, 4096);
+       }
+       World_Clear(&cl.world);
+
+       // load or reload .loc file for team chat messages
+       CL_Locs_Reload_f();
+
+       // reset particles and other per-level things
+       R_Modules_NewMap();
+
+       // load the team chat beep if possible
+       cl.foundtalk2wav = FS_FileExists("sound/misc/talk2.wav");
+
+       // check memory integrity
+       Mem_CheckSentinelsGlobal();
+
+       // load the csqc now
+       if (cl.loadcsqc)
+       {
+               cl.loadcsqc = false;
+               CL_VM_Init();
+       }
+}
+
 static qboolean QW_CL_CheckOrDownloadFile(const char *filename)
 {
        qfile_t *file;
@@ -410,7 +454,6 @@ static qboolean QW_CL_CheckOrDownloadFile(const char *filename)
        return false;
 }
 
-extern void CL_Locs_Reload_f(void);
 static void QW_CL_ProcessUserInfo(int slot);
 static void QW_CL_RequestNextDownload(void)
 {
@@ -510,13 +553,7 @@ static void QW_CL_RequestNextDownload(void)
 
                // now that we have a world model, set up the world entity, renderer
                // modules and csqc
-               cl.entities[0].render.model = cl.worldmodel = cl.model_precache[1];
-               CL_UpdateRenderEntity(&cl.entities[0].render);
-
-               CL_Locs_Reload_f();
-               R_Modules_NewMap();
-
-               cl.foundtalk2wav = FS_FileExists("sound/misc/talk2.wav");
+               CL_SetupWorldModel();
 
                // add pmodel/emodel CRCs to userinfo
                CL_SetInfo("pmodel", va("%i", FS_CRCFile("progs/player.mdl", NULL)), true, true, true, true);
@@ -534,11 +571,6 @@ static void QW_CL_RequestNextDownload(void)
 
                // done loading
                cl.loadfinished = true;
-               if (cl.loadcsqc)
-               {
-                       cl.loadcsqc = false;
-                       CL_VM_Init();
-               }
                break;
        case dl_sound:
                if (cls.qw_downloadnumber == 0)
@@ -947,17 +979,12 @@ void CL_BeginDownloads(qboolean aborteddownload)
                 && (FS_CRCFile(csqc_progname.string, &progsize) != csqc_progcrc.integer || ((int)progsize != csqc_progsize.integer && csqc_progsize.integer != -1))
                 && !FS_FileExists(va("dlcache/%s.%i.%i", csqc_progname.string, csqc_progsize.integer, csqc_progcrc.integer)))
                {
+                       Con_Printf("Downloading new CSQC code to dlcache/%s.%i.%i\n", csqc_progname.string, csqc_progsize.integer, csqc_progcrc.integer);
                        Cmd_ForwardStringToServer(va("download %s", csqc_progname.string));
                        return;
                }
        }
 
-       if (cl.loadcsqc)
-       {
-               cl.loadcsqc = false;
-               CL_VM_Init();
-       }
-
        if (cl.loadmodel_current < cl.loadmodel_total)
        {
                // loading models
@@ -976,13 +1003,7 @@ void CL_BeginDownloads(qboolean aborteddownload)
                        if (cl.model_precache[cl.loadmodel_current] && cl.model_precache[cl.loadmodel_current]->Draw && cl.loadmodel_current == 1)
                        {
                                // we now have the worldmodel so we can set up the game world
-                               cl.entities[0].render.model = cl.worldmodel = cl.model_precache[1];
-                               CL_UpdateRenderEntity(&cl.entities[0].render);
-                               CL_Locs_Reload_f();
-                               R_Modules_NewMap();
-                               cl.foundtalk2wav = FS_FileExists("sound/misc/talk2.wav");
-                               // check memory integrity
-                               Mem_CheckSentinelsGlobal();
+                               CL_SetupWorldModel();
                                if (!cl.loadfinished && cl_joinbeforedownloadsfinish.integer)
                                {
                                        cl.loadfinished = true;
@@ -1027,13 +1048,7 @@ void CL_BeginDownloads(qboolean aborteddownload)
                                if (cl.downloadmodel_current == 1)
                                {
                                        // the worldmodel failed, but we need to set up anyway
-                                       cl.entities[0].render.model = cl.worldmodel = cl.model_precache[1];
-                                       CL_UpdateRenderEntity(&cl.entities[0].render);
-                                       CL_Locs_Reload_f();
-                                       R_Modules_NewMap();
-                                       cl.foundtalk2wav = FS_FileExists("sound/misc/talk2.wav");
-                                       // check memory integrity
-                                       Mem_CheckSentinelsGlobal();
+                                       CL_SetupWorldModel();
                                        if (!cl.loadfinished && cl_joinbeforedownloadsfinish.integer)
                                        {
                                                cl.loadfinished = true;
@@ -1067,13 +1082,7 @@ void CL_BeginDownloads(qboolean aborteddownload)
                        if (cl.downloadmodel_current == 1)
                        {
                                // we now have the worldmodel so we can set up the game world
-                               cl.entities[0].render.model = cl.worldmodel = cl.model_precache[1];
-                               CL_UpdateRenderEntity(&cl.entities[0].render);
-                               CL_Locs_Reload_f();
-                               R_Modules_NewMap();
-                               cl.foundtalk2wav = FS_FileExists("sound/misc/talk2.wav");
-                               // check memory integrity
-                               Mem_CheckSentinelsGlobal();
+                               CL_SetupWorldModel();
                                if (!cl.loadfinished && cl_joinbeforedownloadsfinish.integer)
                                {
                                        cl.loadfinished = true;
@@ -1146,7 +1155,7 @@ void CL_BeginDownloads_f(void)
 
 void CL_StopDownload(int size, int crc)
 {
-       if (cls.qw_downloadmemory && cls.qw_downloadmemorycursize == size && CRC_Block(cls.qw_downloadmemory, size) == crc)
+       if (cls.qw_downloadmemory && cls.qw_downloadmemorycursize == size && CRC_Block(cls.qw_downloadmemory, cls.qw_downloadmemorycursize) == crc)
        {
                int existingcrc;
                size_t existingsize;
@@ -1184,6 +1193,11 @@ void CL_StopDownload(int size, int crc)
                                FS_Rescan();
                }
        }
+       else if (cls.qw_downloadmemory && size)
+       {
+               Con_Printf("Download \"%s\" is corrupt (%i bytes, %i CRC, should be %i bytes, %i CRC), discarding\n", cls.qw_downloadname, size, crc, (int)cls.qw_downloadmemorycursize, (int)CRC_Block(cls.qw_downloadmemory, cls.qw_downloadmemorycursize));
+               CL_BeginDownloads(true);
+       }
 
        if (cls.qw_downloadmemory)
                Mem_Free(cls.qw_downloadmemory);
@@ -1382,7 +1396,10 @@ void CL_ParseServerInfo (void)
 
        // if server is active, we already began a loading plaque
        if (!sv.active)
+       {
                SCR_BeginLoadingPlaque();
+               S_StopAllSounds();
+       }
 
        // check memory integrity
        Mem_CheckSentinelsGlobal();
@@ -1432,7 +1449,7 @@ void CL_ParseServerInfo (void)
                i = MSG_ReadByte();
                // cl.qw_spectator is an unneeded flag, cl.scores[cl.playerentity].qw_spectator works better (it can be updated by the server during the game)
                //cl.qw_spectator = (i & 128) != 0;
-               cl.playerentity = cl.viewentity = (i & 127) + 1;
+               cl.realplayerentity = cl.playerentity = cl.viewentity = (i & 127) + 1;
                cl.scores = (scoreboard_t *)Mem_Alloc(cls.levelmempool, cl.maxclients*sizeof(*cl.scores));
 
                // get the full level name
@@ -1569,6 +1586,7 @@ void CL_ParseServerInfo (void)
                cl.downloadcsqc = true;
                cl.loadbegun = false;
                cl.loadfinished = false;
+               cl.loadcsqc = true;
        }
 
        // check memory integrity
@@ -1652,7 +1670,7 @@ void CL_MoveLerpEntityStates(entity_t *ent)
                VectorCopy(ent->state_current.origin, ent->persistent.neworigin);
                VectorCopy(ent->state_current.angles, ent->persistent.newangles);
                // reset animation interpolation as well
-               ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_current.frame;
+               ent->render.frame1 = ent->render.frame2 = ent->state_current.frame;
                ent->render.frame1time = ent->render.frame2time = cl.time;
                ent->render.framelerp = 1;
                // reset various persistent stuff
@@ -1881,7 +1899,7 @@ void CL_ParseStatic (int large)
 
 // copy it to the current state
        ent->render.model = cl.model_precache[ent->state_baseline.modelindex];
-       ent->render.frame = ent->render.frame1 = ent->render.frame2 = ent->state_baseline.frame;
+       ent->render.frame1 = ent->render.frame2 = ent->state_baseline.frame;
        ent->render.framelerp = 0;
        // make torchs play out of sync
        ent->render.frame1time = ent->render.frame2time = lhrandom(-10, -1);
@@ -2870,7 +2888,15 @@ static void CL_NetworkTimeReceived(double newtime)
        cl.mtime[0] = newtime;
        if (cls.timedemo || (cl.islocalgame && !sv_fixedframeratesingleplayer.integer) || cl.mtime[1] == cl.mtime[0] || cls.signon < SIGNONS)
                cl.time = cl.mtime[1] = newtime;
-       else if (cls.protocol != PROTOCOL_QUAKEWORLD && !cls.demoplayback)
+       else if (cls.demoplayback)
+       {       
+               // when time falls behind during demo playback it means the cl.mtime[1] was altered
+               // due to a large time gap, so treat it as an instant change in time
+               // (this can also happen during heavy packet loss in the demo)
+               if (cl.time < newtime - 0.1)
+                       cl.mtime[1] = cl.time = newtime;
+       }
+       else if (cls.protocol != PROTOCOL_QUAKEWORLD)
        {
                cl.mtime[1] = max(cl.mtime[1], cl.mtime[0] - 0.1);
                if (developer.integer >= 100 && vid_activewindow)
@@ -2937,7 +2963,6 @@ static void CL_NetworkTimeReceived(double newtime)
 #define SHOWNET(x) if(cl_shownet.integer==2)Con_Printf("%3i:%s\n", msg_readcount-1, x);
 
 //[515]: csqc
-void CL_VM_Init (void);
 qboolean CL_VM_Parse_TempEntity (void);
 void CL_VM_Parse_StuffCmd (const char *msg);
 void CL_VM_Parse_CenterPrint (const char *msg);
@@ -3486,7 +3511,10 @@ void CL_ParseServerMessage(void)
                                if (cl.viewentity >= cl.max_entities)
                                        CL_ExpandEntities(cl.viewentity);
                                // LordHavoc: assume first setview recieved is the real player entity
-                               if (!cl.playerentity)
+                               if (!cl.realplayerentity)
+                                       cl.realplayerentity = cl.viewentity;
+                               // update cl.playerentity to this one if it is a valid player
+                               if (cl.viewentity >= 1 && cl.viewentity <= cl.maxclients)
                                        cl.playerentity = cl.viewentity;
                                break;
 
@@ -3671,12 +3699,14 @@ void CL_ParseServerMessage(void)
                                if(!cl.intermission)
                                        cl.completed_time = cl.time;
                                cl.intermission = 1;
+                               CL_VM_UpdateIntermissionState(cl.intermission);
                                break;
 
                        case svc_finale:
                                if(!cl.intermission)
                                        cl.completed_time = cl.time;
                                cl.intermission = 2;
+                               CL_VM_UpdateIntermissionState(cl.intermission);
                                SCR_CenterPrint(MSG_ReadString ());
                                break;
 
@@ -3684,6 +3714,7 @@ void CL_ParseServerMessage(void)
                                if(!cl.intermission)
                                        cl.completed_time = cl.time;
                                cl.intermission = 3;
+                               CL_VM_UpdateIntermissionState(cl.intermission);
                                SCR_CenterPrint(MSG_ReadString ());
                                break;