]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
cruft removal, general cleanup, fix for delta compression bugs, generic targa writer
authorlordhavoc <lordhavoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 26 Nov 2000 09:22:55 +0000 (09:22 +0000)
committerlordhavoc <lordhavoc@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 26 Nov 2000 09:22:55 +0000 (09:22 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@108 d7cf8633-e32d-0410-b094-e92efae38249

cl_parse.c
gl_draw.c
gl_screen.c
glquake.h
image.c
image.h
progs.h
render.h
sbar.h
server.h
sv_main.c

index 028dda200500bbcde5659ca024179f697ebab831..fe45aeeacf64a0a27f3402fbbdfc07a90609ba75 100644 (file)
@@ -453,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;
@@ -470,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;
@@ -488,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];
@@ -501,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");
@@ -531,12 +538,7 @@ void CL_ParseUpdate (int bits)
                ent->colormap = cl.scores[i-1].colors; // color it
        }
 
-       skin = bits & U_SKIN ? MSG_ReadByte() : baseline->skin;
-       if (skin != ent->skinnum)
-       {
-               ent->skinnum = skin;
-       }
-       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));
 
@@ -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;
+       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_ARMOR)
-               i = MSG_ReadByte ();
-       else
-               i = 0;
-       if (cl.stats[STAT_ARMOR] != i)
-       {
-               cl.stats[STAT_ARMOR] = i;
-//             Sbar_Changed ();
-       }
-
-       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);
 }
 
 /*
@@ -938,7 +887,6 @@ 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");
@@ -946,7 +894,6 @@ void CL_ParseServerMessage (void)
                        break;
                        
                case svc_updatefrags:
-//                     Sbar_Changed ();
                        i = MSG_ReadByte ();
                        if (i >= cl.maxclients)
                                Host_Error ("CL_ParseServerMessage: svc_updatefrags > MAX_SCOREBOARD");
@@ -954,7 +901,6 @@ void CL_ParseServerMessage (void)
                        break;                  
 
                case svc_updatecolors:
-//                     Sbar_Changed ();
                        i = MSG_ReadByte ();
                        if (i >= cl.maxclients)
                                Host_Error ("CL_ParseServerMessage: svc_updatecolors > MAX_SCOREBOARD");
index fc666f6f478c18da5bd3195b25d9644dda26e89d..781af9f6a0929f98c25e8583ce7970a9ba06296a 100644 (file)
--- a/gl_draw.c
+++ b/gl_draw.c
@@ -222,7 +222,9 @@ qpic_t      *Draw_CachePic (char *path)
        pic->pic.height = dat->height;
 
        gl = (glpic_t *)pic->pic.data;
-       gl->texnum = GL_LoadPicTexture (dat);
+       gl->texnum = loadtextureimage(path, 0, 0, false, false);
+       if (!gl->texnum)
+               gl->texnum = GL_LoadPicTexture (dat);
        gl->sl = 0;
        gl->sh = 1;
        gl->tl = 0;
index fed3a177523daa7190799c335eb73aa2bf09768e..09e5ae0346bf637610fa1e6691d2681db2f52c8f 100644 (file)
@@ -270,9 +270,6 @@ static void SCR_CalcRefdef (void)
        scr_fullupdate = 0;             // force a background redraw
        vid.recalc_refdef = 0;
 
-// force the status bar to redraw
-//     Sbar_Changed ();
-
 //========================================
        
 // bound viewsize
@@ -586,15 +583,6 @@ void SCR_DrawConsole (void)
 ============================================================================== 
 */ 
 
-typedef struct _TargaHeader {
-       unsigned char   id_length, colormap_type, image_type;
-       unsigned short  colormap_index, colormap_length;
-       unsigned char   colormap_size;
-       unsigned short  x_origin, y_origin, width, height;
-       unsigned char   pixel_size, attributes;
-} TargaHeader;
-
-
 /* 
 ================== 
 SCR_ScreenShot_f
@@ -603,21 +591,21 @@ SCR_ScreenShot_f
 void SCR_ScreenShot_f (void) 
 {
        byte            *buffer;
-       char            pcxname[80]; 
+       char            filename[80]; 
        char            checkname[MAX_OSPATH];
-       int                     i, c, temp;
+       int                     i;
 // 
 // find a file name to save it to 
 // 
-       strcpy(pcxname,"dp0000.tga");
+       strcpy(filename,"dp0000.tga");
                
        for (i=0 ; i<=9999 ; i++) 
        { 
-               pcxname[2] = (i/1000)%10 + '0'; 
-               pcxname[3] = (i/ 100)%10 + '0'; 
-               pcxname[4] = (i/  10)%10 + '0'; 
-               pcxname[5] = (i/   1)%10 + '0'; 
-               sprintf (checkname, "%s/%s", com_gamedir, pcxname);
+               filename[2] = (i/1000)%10 + '0'; 
+               filename[3] = (i/ 100)%10 + '0'; 
+               filename[4] = (i/  10)%10 + '0'; 
+               filename[5] = (i/   1)%10 + '0'; 
+               sprintf (checkname, "%s/%s", com_gamedir, filename);
                if (Sys_FileTime(checkname) == -1)
                        break;  // file doesn't exist
        } 
@@ -627,31 +615,12 @@ void SCR_ScreenShot_f (void)
                return;
        }
 
-
-       buffer = malloc(glwidth*glheight*3 + 18);
-       memset (buffer, 0, 18);
-       buffer[2] = 2;          // uncompressed type
-       buffer[12] = glwidth&255;
-       buffer[13] = glwidth>>8;
-       buffer[14] = glheight&255;
-       buffer[15] = glheight>>8;
-       buffer[16] = 24;        // pixel size
-
-       if (r_render.value)
-               glReadPixels (glx, gly, glwidth, glheight, GL_RGB, GL_UNSIGNED_BYTE, buffer+18 ); 
-
-       // swap rgb to bgr
-       c = 18+glwidth*glheight*3;
-       for (i=18 ; i<c ; i+=3)
-       {
-               temp = buffer[i];
-               buffer[i] = buffer[i+2];
-               buffer[i+2] = temp;
-       }
-       COM_WriteFile (pcxname, buffer, glwidth*glheight*3 + 18 );
+       buffer = malloc(glwidth*glheight*3);
+       glReadPixels (glx, gly, glwidth, glheight, GL_RGB, GL_UNSIGNED_BYTE, buffer); 
+       Image_WriteTGARGB(filename, glwidth, glheight, buffer);
 
        free (buffer);
-       Con_Printf ("Wrote %s\n", pcxname);
+       Con_Printf ("Wrote %s\n", filename);
 } 
 
 
@@ -680,7 +649,6 @@ void SCR_BeginLoadingPlaque (void)
 
        scr_drawloading = true;
        scr_fullupdate = 0;
-//     Sbar_Changed ();
        SCR_UpdateScreen ();
        scr_drawloading = false;
 
index 11d191f9b98b3845a64b2037673a3a73b8297f44..37a53bebd3c32c2cd8e037bba739be543308b967 100644 (file)
--- a/glquake.h
+++ b/glquake.h
@@ -245,3 +245,4 @@ extern void R_DrawAliasModel (entity_t *ent, int cull, float alpha, model_t *clm
 
 extern cvar_t r_render;
 extern cvar_t r_upload;
+#include "image.h"
diff --git a/image.c b/image.c
index a7f3b8ca37a7c6e6f2e688c2e68f5dbdf469e2d7..368bb1f802d79135c4b44c4a3eb00ec000f50107 100644 (file)
--- a/image.c
+++ b/image.c
@@ -511,3 +511,32 @@ int loadtextureimagewithmask (char* filename, int matchwidth, int matchheight, q
        free(data);
        return texnum;
 }
+
+void Image_WriteTGARGB (char *filename, int width, int height, byte *data)
+{
+       byte *buffer, *in, *out, *end;
+
+       buffer = malloc(width*height*3 + 18);
+
+       memset (buffer, 0, 18);
+       buffer[2] = 2;          // uncompressed type
+       buffer[12] = (width >> 0) & 0xFF;
+       buffer[13] = (width >> 8) & 0xFF;
+       buffer[14] = (height >> 0) & 0xFF;
+       buffer[15] = (height >> 8) & 0xFF;
+       buffer[16] = 24;        // pixel size
+
+       // swap rgb to bgr
+       in = data;
+       end = in + width*height*3;
+       out = buffer + 18;
+       for (;in < end;in += 3)
+       {
+               *out++ = in[2];
+               *out++ = in[1];
+               *out++ = in[0];
+       }
+       COM_WriteFile (filename, buffer, glwidth*glheight*3 + 18 );
+
+       free(buffer);
+}
diff --git a/image.h b/image.h
index d0dc56321643d73d8cd97a3f02d36c6ffc080667..c0d07ee7452acda4b6eb3a23677b2c1ea2cfcf9c 100644 (file)
--- a/image.h
+++ b/image.h
@@ -2,7 +2,10 @@
 extern void Image_Copy8bitRGBA(byte *in, byte *out, int pixels, int *pal);
 extern void Image_CopyRGBAGamma(byte *in, byte *out, int pixels);
 extern int image_makemask (byte *in, byte *out, int size);
+extern byte* loadimagepixels (char* filename, qboolean complain, int matchwidth, int matchheight);
+extern int loadtextureimage (char* filename, int matchwidth, int matchheight, qboolean complain, qboolean mipmap);
 extern byte* loadimagepixelsmask (char* filename, qboolean complain, int matchwidth, int matchheight);
 extern int loadtextureimagemask (char* filename, int matchwidth, int matchheight, qboolean complain, qboolean mipmap);
 extern int image_masktexnum;
 extern int loadtextureimagewithmask (char* filename, int matchwidth, int matchheight, qboolean complain, qboolean mipmap);
+extern void Image_WriteTGARGB (char *filename, int width, int height, byte *data);
diff --git a/progs.h b/progs.h
index 485280f6188925a9f88abd5354f044cdfb3a5211..d38eb92578b4f127cd0b98545c1dff8d55f7eb6e 100644 (file)
--- a/progs.h
+++ b/progs.h
@@ -51,8 +51,6 @@ typedef struct edict_s
        vec3_t          stepoldorigin;
        vec3_t          stepoldangles;
        float           steplerptime;
-       // LordHavoc: delta compression
-       float           nextfullupdate; // every second a full update is forced
        entvars_t       v;                                      // C exported fields from progs
 // other fields from progs come immediately after
 } edict_t;
index 2347d941c9e7d9b9f40127741ab871563d2aee39..88b8b245811ab9a9115b4e0d943682cdc2f8afbf 100644 (file)
--- a/render.h
+++ b/render.h
@@ -126,10 +126,6 @@ extern vec3_t      r_origin, vpn, vright, vup;
 
 extern struct texture_s        *r_notexture_mip;
 
-// LordHavoc: generic image loader
-byte* loadimagepixels (char* filename, qboolean complain, int matchwidth, int matchheight);
-int loadtextureimage (char* filename, int matchwidth, int matchheight, qboolean complain, qboolean mipmap);
-
 void R_Init (void);
 void R_InitTextures (void);
 void R_InitEfrags (void);
diff --git a/sbar.h b/sbar.h
index 9e881c84ee2c42e75854c27b6ebf817babc9d423..4a9a60e2e93bf4f05bda7255f442d27c6f3aa3eb 100644 (file)
--- a/sbar.h
+++ b/sbar.h
@@ -24,9 +24,6 @@ extern        int                     sb_lines;                       // scan lines to draw
 
 void Sbar_Init (void);
 
-void Sbar_Changed (void);
-// call whenever any of the client stats represented on the sbar changes
-
 void Sbar_Draw (void);
 // called every frame by screen
 
index 7cc93b18988c0a09606952a07da22616de943464..c377acdc0dcc5b5225911e7a7be953e515726f84 100644 (file)
--- a/server.h
+++ b/server.h
@@ -105,6 +105,9 @@ typedef struct client_s
 // client known data for deltas        
        int                             old_frags;
        int                             pmodel;
+
+       // delta compression state
+       float                   nextfullupdate[MAX_EDICTS];
 } client_t;
 
 
index a22d9395cbfcbaf99effde9ce4f0791f6b4b1c56..ee8f980052182c83dface86e86639924f7ad82c9 100644 (file)
--- a/sv_main.c
+++ b/sv_main.c
@@ -422,7 +422,7 @@ SV_WriteEntitiesToClient
 
 =============
 */
-void SV_WriteEntitiesToClient (edict_t *clent, sizebuf_t *msg)
+void SV_WriteEntitiesToClient (client_t *client, edict_t *clent, sizebuf_t *msg)
 {
        int             e, i, clentnum, bits, alpha, glowcolor, glowsize, scale, colormod, modred, modgreen, modblue, dodelta, effects;
        byte    *pvs;
@@ -549,7 +549,7 @@ void SV_WriteEntitiesToClient (edict_t      *clent, sizebuf_t *msg)
 
                dodelta = FALSE;
                if ((int)ent->v.effects & EF_DELTA)
-                       dodelta = cl.time < ent->nextfullupdate; // every half second a full update is forced
+                       dodelta = cl.time < client->nextfullupdate[e]; // every half second a full update is forced
 
                if (dodelta)
                {
@@ -558,7 +558,7 @@ void SV_WriteEntitiesToClient (edict_t      *clent, sizebuf_t *msg)
                }
                else
                {
-                       ent->nextfullupdate = cl.time + 0.5;
+                       client->nextfullupdate[e] = cl.time + 0.5;
                        baseline = &ent->baseline;
                }
 
@@ -880,7 +880,7 @@ qboolean SV_SendClientDatagram (client_t *client)
 // add the client specific data to the datagram
        SV_WriteClientdataToMessage (client->edict, &msg);
 
-       SV_WriteEntitiesToClient (client->edict, &msg);
+       SV_WriteEntitiesToClient (client, client->edict, &msg);
 
 // copy the server datagram if there is space
        if (msg.cursize + sv.datagram.cursize < msg.maxsize)