]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - cl_parse.c
rewrite of map texture loading (mainly to do with HL textures and wads)
[xonotic/darkplaces.git] / cl_parse.c
index b1f240b073493384256b3de6df599c4f3c17ba49..0d776abff948e84593a95c23b6ee3daa19e4a44a 100644 (file)
@@ -21,7 +21,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "quakedef.h"
 
-char *svc_strings[] =
+char *svc_strings[128] =
 {
        "svc_bad",
        "svc_nop",
@@ -80,13 +80,15 @@ char *svc_strings[] =
        "?", // 47
        "?", // 48
        "?", // 49
-       "svc_skyboxsize", // [coord] size
-       "svc_fog" // [byte] enable <optional past this point, only included if enable is true> [short * 4096] density [byte] red [byte] green [byte] blue
+       "svc_farclip", // [coord] size
+       "svc_fog", // [byte] enable <optional past this point, only included if enable is true> [short] density*4096 [byte] red [byte] green [byte] blue
+       "svc_playerposition" // [float] x [float] y [float] z
 };
 
 //=============================================================================
 
-int Nehahrademcompatibility; // LordHavoc: to allow playback of the early Nehahra movie segments
+qboolean Nehahrademcompatibility; // LordHavoc: to allow playback of the early Nehahra movie segments
+qboolean dpprotocol; // LordHavoc: whether or not the current network stream is the enhanced DarkPlaces protocol
 
 /*
 ===============
@@ -103,7 +105,7 @@ entity_t    *CL_EntityNum (int num)
                        Host_Error ("CL_EntityNum: %i is an invalid number",num);
                while (cl.num_entities<=num)
                {
-                       cl_entities[cl.num_entities].colormap = vid.colormap;
+                       cl_entities[cl.num_entities].colormap = -1; // no special coloring
                        cl.num_entities++;
                }
        }
@@ -217,22 +219,19 @@ void CL_KeepaliveMessage (void)
 
 extern qboolean isworldmodel;
 extern char skyname[];
-extern float fog_density;
-extern float fog_red;
-extern float fog_green;
-extern float fog_blue;
 extern void R_SetSkyBox (char *sky);
 extern void FOG_clear();
+extern cvar_t r_farclip;
 
 void CL_ParseEntityLump(char *entdata)
 {
        char *data;
-       char key[128], value[1024];
+       char key[128], value[4096];
        char wadname[128];
        int i, j, k;
        FOG_clear(); // LordHavoc: no fog until set
        skyname[0] = 0; // LordHavoc: no enviroment mapped sky until set
-//     r_skyboxsize.value = 4096; // LordHavoc: default skyboxsize
+       r_farclip.value = 6144; // LordHavoc: default farclip distance
        data = entdata;
        if (!data)
                return;
@@ -261,12 +260,12 @@ void CL_ParseEntityLump(char *entdata)
                        R_SetSkyBox(value);
                else if (!strcmp("qlsky", key)) // non-standard, introduced by QuakeLives (EEK)
                        R_SetSkyBox(value);
-//             else if (!strcmp("skyboxsize", key))
-//             {
-//                     r_skyboxsize.value = atof(value);
-//                     if (r_skyboxsize.value < 64)
-//                             r_skyboxsize.value = 64;
-//             }
+               else if (!strcmp("farclip", key))
+               {
+                       r_farclip.value = atof(value);
+                       if (r_farclip.value < 64)
+                               r_farclip.value = 64;
+               }
                else if (!strcmp("fog", key))
                {
                        scanf(value, "%f %f %f %f", &fog_density, &fog_red, &fog_green, &fog_blue);
@@ -283,12 +282,12 @@ void CL_ParseEntityLump(char *entdata)
                else if (!strcmp("wad", key)) // for HalfLife maps
                {
                        j = 0;
-                       for (i = 0;i < 128;i++)
+                       for (i = 0;i < 4096;i++)
                                if (value[i] != ';' && value[i] != '\\' && value[i] != '/' && value[i] != ':')
                                        break;
                        if (value[i])
                        {
-                               for (;i < 128;i++)
+                               for (;i < 4096;i++)
                                {
                                        // ignore path - the \\ check is for HalfLife... stupid windoze 'programmers'...
                                        if (value[i] == '\\' || value[i] == '/' || value[i] == ':')
@@ -299,7 +298,7 @@ void CL_ParseEntityLump(char *entdata)
                                                value[i] = 0;
                                                strcpy(wadname, "textures/");
                                                strcat(wadname, &value[j]);
-                                               W_LoadTextureWadFile (wadname, FALSE);
+                                               W_LoadTextureWadFile (wadname, false);
                                                j = i+1;
                                                if (!k)
                                                        break;
@@ -332,9 +331,9 @@ void CL_ParseServerInfo (void)
 
 // parse protocol version number
        i = MSG_ReadLong ();
-       if (i != PROTOCOL_VERSION && i != 250)
+       if (i != PROTOCOL_VERSION && i != DPPROTOCOL_VERSION && i != 250)
        {
-               Con_Printf ("Server returned version %i, not %i", i, PROTOCOL_VERSION);
+               Con_Printf ("Server returned version %i, not %i or %i", i, DPPROTOCOL_VERSION, PROTOCOL_VERSION);
                return;
        }
        Nehahrademcompatibility = false;
@@ -342,6 +341,7 @@ void CL_ParseServerInfo (void)
                Nehahrademcompatibility = true;
        if (cls.demoplayback && demo_nehahra.value)
                Nehahrademcompatibility = true;
+       dpprotocol = i == DPPROTOCOL_VERSION;
 
 // parse maxclients
        cl.maxclients = MSG_ReadByte ();
@@ -384,6 +384,8 @@ void CL_ParseServerInfo (void)
                        Con_Printf ("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);
        }
@@ -400,6 +402,8 @@ void CL_ParseServerInfo (void)
                        Con_Printf ("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);
        }
@@ -449,11 +453,9 @@ If an entities model or origin changes from frame to frame, it must be
 relinked.  Other attributes can change without relinking.
 ==================
 */
-//int  bitcounts[16];
-
 void CL_ParseUpdate (int bits)
 {
-       int                     i, modnum, num, skin, alpha, scale, glowsize, glowcolor, colormod;
+       int                     i, modnum, num, alpha, scale, glowsize, glowcolor, colormod;
        model_t         *model;
        qboolean        forcelink;
        entity_t        *ent;
@@ -466,10 +468,7 @@ void CL_ParseUpdate (int bits)
        }
 
        if (bits & U_MOREBITS)
-       {
-               i = MSG_ReadByte ();
-               bits |= (i<<8);
-       }
+               bits |= (MSG_ReadByte()<<8);
        if (bits & U_EXTEND1 && !Nehahrademcompatibility)
        {
                bits |= MSG_ReadByte() << 16;
@@ -484,10 +483,6 @@ void CL_ParseUpdate (int bits)
 
        ent = CL_EntityNum (num);
 
-//for (i=0 ; i<16 ; i++)
-//if (bits&(1<<i))
-//     bitcounts[i]++;
-
        forcelink = ent->msgtime != cl.mtime[1]; // no previous frame to lerp from
 
        ent->msgtime = cl.mtime[0];
@@ -497,6 +492,22 @@ void CL_ParseUpdate (int bits)
        if (bits & U_DELTA)
                baseline = &ent->deltabaseline;
 
+       if (forcelink)
+       {
+               ent->deltabaseline.origin[0] = ent->deltabaseline.origin[1] = ent->deltabaseline.origin[2] = 0;
+               ent->deltabaseline.angles[0] = ent->deltabaseline.angles[1] = ent->deltabaseline.angles[2] = 0;
+               ent->deltabaseline.effects = 0;
+               ent->deltabaseline.modelindex = 0;
+               ent->deltabaseline.frame = 0;
+               ent->deltabaseline.colormap = 0;
+               ent->deltabaseline.skin = 0;
+               ent->deltabaseline.alpha = 255;
+               ent->deltabaseline.scale = 16;
+               ent->deltabaseline.glowsize = 0;
+               ent->deltabaseline.glowcolor = 254;
+               ent->deltabaseline.colormod = 255;
+       }
+
        modnum = bits & U_MODEL ? MSG_ReadByte() : baseline->modelindex;
        if (modnum >= MAX_MODELS)
                Host_Error ("CL_ParseModel: bad modnum");
@@ -512,8 +523,6 @@ void CL_ParseUpdate (int bits)
                        ent->syncbase = model->synctype == ST_RAND ? (float)(rand()&0x7fff) / 0x7fff : 0.0;
                else
                        forcelink = true;       // hack to make null model players work
-               if (num > 0 && num <= cl.maxclients)
-                       R_TranslatePlayerSkin (num - 1);
        }
 
        ent->frame = ((bits & U_FRAME) ? MSG_ReadByte() : (baseline->frame & 0xFF));
@@ -521,22 +530,15 @@ void CL_ParseUpdate (int bits)
        i = bits & U_COLORMAP ? MSG_ReadByte() : baseline->colormap;
        ent->deltabaseline.colormap = i;
        if (!i)
-               ent->colormap = vid.colormap;
+               ent->colormap = -1; // no special coloring
        else
        {
                if (i > cl.maxclients)
                        Host_Error ("i >= cl.maxclients");
-               ent->colormap = vid.colormap; // cl.scores[i-1].translations;
+               ent->colormap = cl.scores[i-1].colors; // color it
        }
 
-       skin = bits & U_SKIN ? MSG_ReadByte() : baseline->skin;
-       if (skin != ent->skinnum)
-       {
-               ent->skinnum = skin;
-               if (num > 0 && num <= cl.maxclients)
-                       R_TranslatePlayerSkin (num - 1);
-       }
-       ent->deltabaseline.skin = skin;
+       ent->deltabaseline.skin = ent->skinnum = bits & U_SKIN ? MSG_ReadByte() : baseline->skin;
 
        ent->effects = ((bits & U_EFFECTS) ? MSG_ReadByte() : (baseline->effects & 0xFF));
 
@@ -572,7 +574,7 @@ void CL_ParseUpdate (int bits)
        ent->deltabaseline.frame = ent->frame;
        ent->alpha = (float) alpha * (1.0 / 255.0);
        ent->scale = (float) scale * (1.0 / 16.0);
-       ent->glowsize = glowsize < 128 ? glowsize * 8.0 : (glowsize - 256) * 8.0;
+       ent->glowsize = glowsize * 4.0;
        ent->glowcolor = glowcolor;
        ent->colormod[0] = (float) ((colormod >> 5) & 7) * (1.0 / 7.0);
        ent->colormod[1] = (float) ((colormod >> 2) & 7) * (1.0 / 7.0);
@@ -661,12 +663,9 @@ void CL_ParseClientdata (int bits)
                        cl.mvelocity[0][i] = 0;
        }
 
-// [always sent]       if (bits & SU_ITEMS)
-               i = MSG_ReadLong ();
-
+       i = MSG_ReadLong ();
        if (cl.items != i)
        {       // set flash times
-//             Sbar_Changed ();
                for (j=0 ; j<32 ; j++)
                        if ( (i & (1<<j)) && !(cl.items & (1<<j)))
                                cl.item_gettime[j] = cl.time;
@@ -676,73 +675,23 @@ void CL_ParseClientdata (int bits)
        cl.onground = (bits & SU_ONGROUND) != 0;
        cl.inwater = (bits & SU_INWATER) != 0;
 
-       if (bits & SU_WEAPONFRAME)
-               cl.stats[STAT_WEAPONFRAME] = MSG_ReadByte ();
-       else
-               cl.stats[STAT_WEAPONFRAME] = 0;
-
-       if (bits & SU_ARMOR)
-               i = MSG_ReadByte ();
-       else
-               i = 0;
-       if (cl.stats[STAT_ARMOR] != i)
-       {
-               cl.stats[STAT_ARMOR] = i;
-//             Sbar_Changed ();
-       }
+       cl.stats[STAT_WEAPONFRAME] = (bits & SU_WEAPONFRAME) ? MSG_ReadByte() : 0;
+       cl.stats[STAT_ARMOR] = (bits & SU_ARMOR) ? MSG_ReadByte() : 0;
+       cl.stats[STAT_WEAPON] = (bits & SU_WEAPON) ? MSG_ReadByte() : 0;
+       cl.stats[STAT_HEALTH] = MSG_ReadShort();
+       cl.stats[STAT_AMMO] = MSG_ReadByte();
 
-       if (bits & SU_WEAPON)
-               i = MSG_ReadByte ();
-       else
-               i = 0;
-       if (cl.stats[STAT_WEAPON] != i)
-       {
-               cl.stats[STAT_WEAPON] = i;
-//             Sbar_Changed ();
-       }
-       
-       i = MSG_ReadShort ();
-       if (cl.stats[STAT_HEALTH] != i)
-       {
-               cl.stats[STAT_HEALTH] = i;
-//             Sbar_Changed ();
-       }
-
-       i = MSG_ReadByte ();
-       if (cl.stats[STAT_AMMO] != i)
-       {
-               cl.stats[STAT_AMMO] = i;
-//             Sbar_Changed ();
-       }
-
-       for (i=0 ; i<4 ; i++)
-       {
-               j = MSG_ReadByte ();
-               if (cl.stats[STAT_SHELLS+i] != j)
-               {
-                       cl.stats[STAT_SHELLS+i] = j;
-//                     Sbar_Changed ();
-               }
-       }
+       cl.stats[STAT_SHELLS] = MSG_ReadByte();
+       cl.stats[STAT_NAILS] = MSG_ReadByte();
+       cl.stats[STAT_ROCKETS] = MSG_ReadByte();
+       cl.stats[STAT_CELLS] = MSG_ReadByte();
 
        i = MSG_ReadByte ();
 
        if (standard_quake)
-       {
-               if (cl.stats[STAT_ACTIVEWEAPON] != i)
-               {
-                       cl.stats[STAT_ACTIVEWEAPON] = i;
-//                     Sbar_Changed ();
-               }
-       }
+               cl.stats[STAT_ACTIVEWEAPON] = i;
        else
-       {
-               if (cl.stats[STAT_ACTIVEWEAPON] != (1<<i))
-               {
-                       cl.stats[STAT_ACTIVEWEAPON] = (1<<i);
-//                     Sbar_Changed ();
-               }
-       }
+               cl.stats[STAT_ACTIVEWEAPON] = (1<<i);
 }
 
 /*
@@ -765,7 +714,7 @@ void CL_ParseStatic (void)
 // copy it to the current state
        ent->model = cl.model_precache[ent->baseline.modelindex];
        ent->frame = ent->baseline.frame;
-       ent->colormap = vid.colormap;
+       ent->colormap = -1; // no special coloring
        ent->skinnum = ent->baseline.skin;
        ent->effects = ent->baseline.effects;
        ent->alpha = 1;
@@ -807,11 +756,6 @@ extern void SHOWLMP_decodehide();
 extern void SHOWLMP_decodeshow();
 extern void R_SetSkyBox(char* sky);
 
-extern float fog_density;
-extern float fog_red;
-extern float fog_green;
-extern float fog_blue;
-
 /*
 =====================
 CL_ParseServerMessage
@@ -821,6 +765,9 @@ void CL_ParseServerMessage (void)
 {
        int                     cmd;
        int                     i;
+       byte            cmdlog[32];
+       char            *cmdlogname[32], *temp;
+       int                     cmdindex, cmdcount = 0;
        
 //
 // if recording demos, copy the message out
@@ -849,21 +796,55 @@ void CL_ParseServerMessage (void)
                        return;         // end of message
                }
 
-       // if the high bit of the command byte is set, it is a fast update
+               cmdindex = cmdcount & 31;
+               cmdcount++;
+               cmdlog[cmdindex] = cmd;
+
+               // if the high bit of the command byte is set, it is a fast update
                if (cmd & 128)
                {
+                       // LordHavoc: fix for bizarre problem in MSVC that I do not understand (if I assign the string pointer directly it ends up storing a NULL pointer)
+                       temp = "svc_entity";
+                       cmdlogname[cmdindex] = temp;
                        SHOWNET("fast update");
                        CL_ParseUpdate (cmd&127);
                        continue;
                }
 
                SHOWNET(svc_strings[cmd]);
+               cmdlogname[cmdindex] = svc_strings[cmd];
+               if (!cmdlogname[cmdindex])
+               {
+                       // LordHavoc: fix for bizarre problem in MSVC that I do not understand (if I assign the string pointer directly it ends up storing a NULL pointer)
+                       temp = "<unknown>";
+                       cmdlogname[cmdindex] = temp;
+               }
        
-       // other commands
+               // other commands
                switch (cmd)
                {
                default:
-                       Host_Error ("CL_ParseServerMessage: Illegible server message\n");
+                       {
+                               char description[32*64], temp[64];
+                               int count;
+                               strcpy(description, "packet dump: ");
+                               i = cmdcount - 32;
+                               if (i < 0)
+                                       i = 0;
+                               count = cmdcount - i;
+                               i &= 31;
+                               while(count > 0)
+                               {
+                                       sprintf(temp, "%3i:%s ", cmdlog[i], cmdlogname[i]);
+                                       strcat(description, temp);
+                                       count--;
+                                       i++;
+                                       i &= 31;
+                               }
+                               description[strlen(description)-1] = '\n'; // replace the last space with a newline
+                               Con_Printf(description);
+                               Host_Error ("CL_ParseServerMessage: Illegible server message\n");
+                       }
                        break;
                        
                case svc_nop:
@@ -882,9 +863,17 @@ void CL_ParseServerMessage (void)
                
                case svc_version:
                        i = MSG_ReadLong ();
-                       if (i != PROTOCOL_VERSION && i != 250)
-                               Host_Error ("CL_ParseServerMessage: Server is protocol %i instead of %i\n", i, PROTOCOL_VERSION);
-                       Nehahrademcompatibility = i == 250;
+                       if (i != PROTOCOL_VERSION && i != DPPROTOCOL_VERSION && i != 250)
+                       {
+                               Host_Error ("CL_ParseServerMessage: Server is protocol %i, not %i or %i", i, DPPROTOCOL_VERSION, PROTOCOL_VERSION);
+                               return;
+                       }
+                       Nehahrademcompatibility = false;
+                       if (i == 250)
+                               Nehahrademcompatibility = true;
+                       if (cls.demoplayback && demo_nehahra.value)
+                               Nehahrademcompatibility = true;
+                       dpprotocol = i == DPPROTOCOL_VERSION;
                        break;
                        
                case svc_disconnect:
@@ -924,7 +913,8 @@ void CL_ParseServerMessage (void)
                        i = MSG_ReadByte ();
                        if (i >= MAX_LIGHTSTYLES)
                                Host_Error ("svc_lightstyle > MAX_LIGHTSTYLES");
-                       strcpy (cl_lightstyle[i].map,  MSG_ReadString());
+                       strncpy (cl_lightstyle[i].map,  MSG_ReadString(), MAX_STYLESTRING - 1);
+                       cl_lightstyle[i].map[MAX_STYLESTRING - 1] = 0;
                        cl_lightstyle[i].length = strlen(cl_lightstyle[i].map);
                        break;
                        
@@ -938,28 +928,24 @@ void CL_ParseServerMessage (void)
                        break;
                
                case svc_updatename:
-//                     Sbar_Changed ();
                        i = MSG_ReadByte ();
                        if (i >= cl.maxclients)
-                               Host_Error ("CL_ParseServerMessage: svc_updatename > MAX_SCOREBOARD");
+                               Host_Error ("CL_ParseServerMessage: svc_updatename >= MAX_SCOREBOARD");
                        strcpy (cl.scores[i].name, MSG_ReadString ());
                        break;
                        
                case svc_updatefrags:
-//                     Sbar_Changed ();
                        i = MSG_ReadByte ();
                        if (i >= cl.maxclients)
-                               Host_Error ("CL_ParseServerMessage: svc_updatefrags > MAX_SCOREBOARD");
+                               Host_Error ("CL_ParseServerMessage: svc_updatefrags >= MAX_SCOREBOARD");
                        cl.scores[i].frags = MSG_ReadShort ();
                        break;                  
 
                case svc_updatecolors:
-//                     Sbar_Changed ();
                        i = MSG_ReadByte ();
                        if (i >= cl.maxclients)
-                               Host_Error ("CL_ParseServerMessage: svc_updatecolors > MAX_SCOREBOARD");
+                               Host_Error ("CL_ParseServerMessage: svc_updatecolors >= MAX_SCOREBOARD");
                        cl.scores[i].colors = MSG_ReadByte ();
-                       R_TranslatePlayerSkin (i);
                        break;
                        
                case svc_particle:
@@ -979,24 +965,11 @@ void CL_ParseServerMessage (void)
                        break;
 
                case svc_setpause:
-                       {
-                               cl.paused = MSG_ReadByte ();
-
-                               if (cl.paused)
-                               {
-                                       CDAudio_Pause ();
-#ifdef _WIN32
-                                       VID_HandlePause (true);
-#endif
-                               }
-                               else
-                               {
-                                       CDAudio_Resume ();
-#ifdef _WIN32
-                                       VID_HandlePause (false);
-#endif
-                               }
-                       }
+                       cl.paused = MSG_ReadByte ();
+                       if (cl.paused)
+                               CDAudio_Pause ();
+                       else
+                               CDAudio_Resume ();
                        break;
                        
                case svc_signonnum:
@@ -1019,7 +992,7 @@ void CL_ParseServerMessage (void)
                        i = MSG_ReadByte ();
                        if (i < 0 || i >= MAX_CL_STATS)
                                Host_Error ("svc_updatestat: %i is invalid", i);
-                       cl.stats[i] = MSG_ReadLong ();;
+                       cl.stats[i] = MSG_ReadLong ();
                        break;
                        
                case svc_spawnstaticsound:
@@ -1064,12 +1037,12 @@ void CL_ParseServerMessage (void)
                case svc_showlmp:
                        SHOWLMP_decodeshow();
                        break;
-       // LordHavoc: extra worldspawn fields (fog, sky, skyboxsize)
+       // LordHavoc: extra worldspawn fields (fog, sky, farclip)
                case svc_skybox:
                        R_SetSkyBox(MSG_ReadString());
                        break;
-               case svc_skyboxsize:
-                       /*r_skyboxsize.value = */MSG_ReadCoord();
+               case svc_farclip:
+                       r_farclip.value = MSG_ReadCoord();
                        break;
                case svc_fog:
                        if (MSG_ReadByte())