]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_parse.c
MAX_EDICTS has changed to 32768. Yes this is madness. Thanks to banshee for prompti...
[xonotic/darkplaces.git] / cl_parse.c
index 608b3ef882a7a4840fc69d855be2f30d8a743c45..b15f72cf9ae2139625a7cad867c730ab93c1efb4 100644 (file)
@@ -113,21 +113,32 @@ void CL_ParseStartSoundPacket(int largesoundindex)
     int        field_mask;
     float      attenuation;
        int             i;
-                  
+
     field_mask = MSG_ReadByte();
 
     if (field_mask & SND_VOLUME)
                volume = MSG_ReadByte ();
        else
                volume = DEFAULT_SOUND_PACKET_VOLUME;
-       
+
     if (field_mask & SND_ATTENUATION)
                attenuation = MSG_ReadByte () / 64.0;
        else
                attenuation = DEFAULT_SOUND_PACKET_ATTENUATION;
-       
-       channel = MSG_ReadShort ();
-       if (largesoundindex)
+
+       if (field_mask & SND_LARGEENTITY)
+       {
+               ent = (unsigned short) MSG_ReadShort ();
+               channel = MSG_ReadByte ();
+       }
+       else
+       {
+               channel = (unsigned short) MSG_ReadShort ();
+               ent = channel >> 3;
+               channel &= 7;
+       }
+
+       if (largesoundindex || field_mask & SND_LARGESOUND)
                sound_num = (unsigned short) MSG_ReadShort ();
        else
                sound_num = MSG_ReadByte ();
@@ -135,13 +146,11 @@ void CL_ParseStartSoundPacket(int largesoundindex)
        if (sound_num >= MAX_SOUNDS)
                Host_Error("CL_ParseStartSoundPacket: sound_num (%i) >= MAX_SOUNDS (%i)\n", sound_num, MAX_SOUNDS);
 
-       ent = channel >> 3;
-       channel &= 7;
 
-       if (ent > MAX_EDICTS)
+       if (ent >= MAX_EDICTS)
                Host_Error ("CL_ParseStartSoundPacket: ent = %i", ent);
-       
-       for (i=0 ; i<3 ; i++)
+
+       for (i = 0;i < 3;i++)
                pos[i] = MSG_ReadCoord ();
 
     S_StartSound (ent, channel, cl.sound_precache[sound_num], pos, volume/255.0, attenuation);
@@ -163,7 +172,7 @@ void CL_KeepaliveMessage (void)
        int             c;
        sizebuf_t       old;
        qbyte           olddata[8192];
-       
+
        if (sv.active)
                return;         // no need if server is local
        if (cls.demoplayback)
@@ -172,7 +181,7 @@ void CL_KeepaliveMessage (void)
 // read messages from server, should just be nops
        old = net_message;
        memcpy (olddata, net_message.data, net_message.cursize);
-       
+
        do
        {
                ret = CL_GetMessage ();
@@ -330,7 +339,7 @@ void CL_ParseServerInfo (void)
        i = MSG_ReadLong ();
        if (i != PROTOCOL_VERSION && i != DPPROTOCOL_VERSION1 && i != DPPROTOCOL_VERSION2 && i != DPPROTOCOL_VERSION3 && i != 250)
        {
-               Con_Printf ("Server is protocol %i, not %i, %i, %i or %i", i, DPPROTOCOL_VERSION1, DPPROTOCOL_VERSION2, DPPROTOCOL_VERSION3, PROTOCOL_VERSION);
+               Host_Error ("Server is protocol %i, not %i, %i, %i or %i", i, DPPROTOCOL_VERSION1, DPPROTOCOL_VERSION2, DPPROTOCOL_VERSION3, PROTOCOL_VERSION);
                return;
        }
        Nehahrademcompatibility = false;
@@ -365,82 +374,76 @@ void CL_ParseServerInfo (void)
                Con_Printf ("%c%s\n", 2, str);
        }
 
-//
-// first we go through and touch all of the precache data that still
-// happens to be in the cache, so precaching something else doesn't
-// needlessly purge it
-//
-
+       // check memory integrity
        Mem_CheckSentinelsGlobal();
 
-       Mod_ClearUsed();
-
        // disable until we get textures for it
        R_ResetSkyBox();
 
-// precache models
        memset (cl.model_precache, 0, sizeof(cl.model_precache));
+       memset (cl.sound_precache, 0, sizeof(cl.sound_precache));
+
+       // touch all of the precached models that are still loaded so we can free
+       // anything that isn't needed
+       Mod_ClearUsed();
        for (nummodels=1 ; ; nummodels++)
        {
+               CL_KeepaliveMessage ();
                str = MSG_ReadString ();
                if (!str[0])
                        break;
                if (nummodels==MAX_MODELS)
-               {
                        Host_Error ("Server sent too many model precaches\n");
-                       return;
-               }
                if (strlen(str) >= MAX_QPATH)
                        Host_Error ("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
                strcpy (model_precache[nummodels], str);
                Mod_TouchModel (str);
        }
 
-// precache sounds
-       memset (cl.sound_precache, 0, sizeof(cl.sound_precache));
+       // do the same for sounds
        for (numsounds=1 ; ; numsounds++)
        {
+               CL_KeepaliveMessage ();
                str = MSG_ReadString ();
                if (!str[0])
                        break;
                if (numsounds==MAX_SOUNDS)
-               {
                        Host_Error ("Server sent too many sound precaches\n");
-                       return;
-               }
                if (strlen(str) >= MAX_QPATH)
                        Host_Error ("Server sent a precache name of %i characters (max %i)", strlen(str), MAX_QPATH - 1);
                strcpy (sound_precache[numsounds], str);
                S_TouchSound (str);
        }
 
+       // purge anything that was not touched
        Mod_PurgeUnused();
 
-//
-// now we try to load everything else until a cache allocation fails
-//
+       // now we try to load everything that is new
+
+       // world model
+       CL_KeepaliveMessage ();
+       cl.model_precache[1] = Mod_ForName (model_precache[1], false, false, true);
+       if (cl.model_precache[1] == NULL)
+               Con_Printf("Map %s not found\n", model_precache[1]);
 
-       for (i=1 ; i<nummodels ; i++)
+       // normal models
+       for (i=2 ; i<nummodels ; i++)
        {
-               // LordHavoc: i == 1 means the first model is the world model
-               cl.model_precache[i] = Mod_ForName (model_precache[i], false, false, i == 1);
-               if (cl.model_precache[i] == NULL)
-               {
-                       Con_Printf("Model %s not found\n", model_precache[i]);
-                       //return;
-               }
                CL_KeepaliveMessage ();
+               if ((cl.model_precache[i] = Mod_ForName (model_precache[i], false, false, false)) == NULL)
+                       Con_Printf("Model %s not found\n", model_precache[i]);
        }
 
+       // sounds
        S_BeginPrecaching ();
        for (i=1 ; i<numsounds ; i++)
        {
-               cl.sound_precache[i] = S_PrecacheSound (sound_precache[i], true);
                CL_KeepaliveMessage ();
+               cl.sound_precache[i] = S_PrecacheSound (sound_precache[i], true);
        }
        S_EndPrecaching ();
 
-// local state
+       // local state
        ent = &cl_entities[0];
        // entire entity array was cleared, so just fill in a few fields
        ent->state_current.active = true;
@@ -456,10 +459,11 @@ void CL_ParseServerInfo (void)
        R_NewMap ();
        CL_CGVM_Start();
 
-       noclip_anglehack = false;               // noclip is turned off at start
+       // noclip is turned off at start
+       noclip_anglehack = false;
 
+       // check memory integrity
        Mem_CheckSentinelsGlobal();
-
 }
 
 void CL_ValidateState(entity_state_t *s)
@@ -508,9 +512,9 @@ void CL_MoveLerpEntityStates(entity_t *ent)
        else// if (ent->state_current.flags & RENDER_STEP)
        {
                // monster interpolation
-               if (DotProduct(odelta, odelta) + DotProduct(adelta, adelta) > 0.01 || cl.mtime[0] - ent->persistent.lerpstarttime >= 0.1)
+               if (DotProduct(odelta, odelta) + DotProduct(adelta, adelta) > 0.01)
                {
-                       ent->persistent.lerpdeltatime = cl.time - ent->persistent.lerpstarttime;
+                       ent->persistent.lerpdeltatime = bound(0, cl.mtime[1] - ent->persistent.lerpstarttime, 0.1);
                        ent->persistent.lerpstarttime = cl.mtime[1];
                        VectorCopy(ent->persistent.neworigin, ent->persistent.oldorigin);
                        VectorCopy(ent->persistent.newangles, ent->persistent.oldangles);
@@ -934,7 +938,7 @@ void CL_InitTEnts (void)
        cl_sfx_r_exp3 = S_PrecacheSound ("weapons/r_exp3.wav", false);
 }
 
-void CL_ParseBeam (model_t *m)
+void CL_ParseBeam (model_t *m, int lightning)
 {
        int i, ent;
        vec3_t start, end;
@@ -944,12 +948,20 @@ void CL_ParseBeam (model_t *m)
        MSG_ReadVector(start);
        MSG_ReadVector(end);
 
+       if (ent >= MAX_EDICTS)
+       {
+               Con_Printf("CL_ParseBeam: invalid entity number %i\n", ent);
+               ent = 0;
+       }
+
        // override any beam with the same entity
        for (i = 0, b = cl_beams;i < cl_max_beams;i++, b++)
        {
                if (b->entity == ent)
                {
                        //b->entity = ent;
+                       b->lightning = lightning;
+                       b->relativestartvalid = (ent && cl_entities[ent].state_current.active) ? 2 : 0;
                        b->model = m;
                        b->endtime = cl.time + 0.2;
                        VectorCopy (start, b->start);
@@ -964,6 +976,8 @@ void CL_ParseBeam (model_t *m)
                if (!b->model || b->endtime < cl.time)
                {
                        b->entity = ent;
+                       b->lightning = lightning;
+                       b->relativestartvalid = (ent && cl_entities[ent].state_current.active) ? 2 : 0;
                        b->model = m;
                        b->endtime = cl.time + 0.2;
                        VectorCopy (start, b->start);
@@ -1251,21 +1265,21 @@ void CL_ParseTempEntity (void)
                // lightning bolts
                if (!cl_model_bolt)
                        cl_model_bolt = Mod_ForName("progs/bolt.mdl", true, false, false);
-               CL_ParseBeam (cl_model_bolt);
+               CL_ParseBeam (cl_model_bolt, true);
                break;
 
        case TE_LIGHTNING2:
                // lightning bolts
                if (!cl_model_bolt2)
                        cl_model_bolt2 = Mod_ForName("progs/bolt2.mdl", true, false, false);
-               CL_ParseBeam (cl_model_bolt2);
+               CL_ParseBeam (cl_model_bolt2, true);
                break;
 
        case TE_LIGHTNING3:
                // lightning bolts
                if (!cl_model_bolt3)
                        cl_model_bolt3 = Mod_ForName("progs/bolt3.mdl", true, false, false);
-               CL_ParseBeam (cl_model_bolt3);
+               CL_ParseBeam (cl_model_bolt3, true);
                break;
 
 // PGM 01/21/97
@@ -1273,13 +1287,13 @@ void CL_ParseTempEntity (void)
                // grappling hook beam
                if (!cl_model_beam)
                        cl_model_beam = Mod_ForName("progs/beam.mdl", true, false, false);
-               CL_ParseBeam (cl_model_beam);
+               CL_ParseBeam (cl_model_beam, false);
                break;
 // PGM 01/21/97
 
 // LordHavoc: for compatibility with the Nehahra movie...
        case TE_LIGHTNING4NEH:
-               CL_ParseBeam (Mod_ForName(MSG_ReadString(), true, false, false));
+               CL_ParseBeam (Mod_ForName(MSG_ReadString(), true, false, false), false);
                break;
 
        case TE_LAVASPLASH:
@@ -1293,7 +1307,7 @@ void CL_ParseTempEntity (void)
                pos[0] = MSG_ReadCoord ();
                pos[1] = MSG_ReadCoord ();
                pos[2] = MSG_ReadCoord ();
-               CL_AllocDlight (NULL, pos, 1000, 1.25f, 1.25f, 1.25f, 3000, 99.0f);
+               CL_AllocDlight (NULL, pos, 500, 1.0f, 1.0f, 1.0f, 1500, 99.0f);
 //             CL_TeleportSplash (pos);
                break;
 
@@ -1304,13 +1318,46 @@ void CL_ParseTempEntity (void)
                colorStart = MSG_ReadByte ();
                colorLength = MSG_ReadByte ();
                CL_ParticleExplosion2 (pos, colorStart, colorLength);
-               tempcolor = (qbyte *)&d_8to24table[(rand()%colorLength) + colorStart];
+               tempcolor = (qbyte *)&palette_complete[(rand()%colorLength) + colorStart];
                CL_AllocDlight (NULL, pos, 350, tempcolor[0] * (1.0f / 255.0f), tempcolor[1] * (1.0f / 255.0f), tempcolor[2] * (1.0f / 255.0f), 700, 0.5);
                S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
                break;
 
+       case TE_TEI_G3:
+               MSG_ReadVector(pos);
+               MSG_ReadVector(pos2);
+               MSG_ReadVector(dir);
+               CL_BeamParticle(pos, pos2, 12, 1, 0.3, 0.1, 1, 1);
+               CL_BeamParticle(pos, pos2, 5, 1, 0.9, 0.3, 1, 1);
+               break;
+
+       case TE_TEI_SMOKE:
+               MSG_ReadVector(pos);
+               MSG_ReadVector(dir);
+               count = MSG_ReadByte ();
+               Mod_FindNonSolidLocation(pos, cl.worldmodel);
+               CL_Tei_Smoke(pos, dir, count);
+               break;
+
+       case TE_TEI_BIGEXPLOSION:
+               MSG_ReadVector(pos);
+               Mod_FindNonSolidLocation(pos, cl.worldmodel);
+               CL_ParticleExplosion (pos);
+               CL_AllocDlight (NULL, pos, 500, 1.25f, 1.0f, 0.5f, 500, 9999);
+               S_StartSound (-1, 0, cl_sfx_r_exp3, pos, 1, 1);
+               break;
+
+       case TE_TEI_PLASMAHIT:
+               MSG_ReadVector(pos);
+               MSG_ReadVector(dir);
+               count = MSG_ReadByte ();
+               Mod_FindNonSolidLocation(pos, cl.worldmodel);
+               CL_Tei_PlasmaHit(pos, dir, count);
+               CL_AllocDlight (NULL, pos, 500, 0.3, 0.6, 1.0f, 2000, 9999);
+               break;
+
        default:
-               Host_Error ("CL_ParseTempEntity: bad type %d", type);
+               Host_Error ("CL_ParseTempEntity: bad type %d (hex %02X)", type, type);
        }
 }
 
@@ -1323,6 +1370,7 @@ static qbyte cgamenetbuffer[65536];
 CL_ParseServerMessage
 =====================
 */
+int parsingerror = false;
 void CL_ParseServerMessage (void)
 {
        int                     cmd;
@@ -1347,6 +1395,8 @@ void CL_ParseServerMessage (void)
 
        entitiesupdated = false;
 
+       parsingerror = true;
+
        while (1)
        {
                if (msg_badread)
@@ -1667,6 +1717,17 @@ void CL_ParseServerMessage (void)
 
        if (entitiesupdated)
                CL_EntityUpdateEnd();
+
+       parsingerror = false;
+}
+
+void CL_Parse_DumpPacket(void)
+{
+       if (!parsingerror)
+               return;
+       Con_Printf("Packet dump:\n");
+       SZ_HexDumpToConsole(&net_message);
+       parsingerror = false;
 }
 
 void CL_Parse_Init(void)