]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - protocol.c
fix compile error
[xonotic/darkplaces.git] / protocol.c
index 748e23b341afce3775aa5456fb5dadfe85f9ca4f..ec69774fd897ece7faae8c8deb901ed0c86d28f8 100644 (file)
@@ -37,7 +37,7 @@ entity_state_t defaultstate =
        0,//unsigned short nodrawtoclient; // !
        0,//unsigned short drawonlytoclient; // !
        {0,0,0,0},//unsigned short light[4]; // color*256 (0.00 to 255.996), and radius*1
-       0,//unsigned char active; // true if a valid state
+       ACTIVE_NOT,//unsigned char active; // true if a valid state
        0,//unsigned char lightstyle;
        0,//unsigned char lightpflags;
        0,//unsigned char colormap;
@@ -50,8 +50,7 @@ entity_state_t defaultstate =
        0,//unsigned char internaleffects; // INTEF_FLAG1QW and so on
        0,//unsigned char tagindex;
        {32, 32, 32},//unsigned char colormod[3];
-       // padding to a multiple of 8 bytes (to align the double time)
-       {0,0,0,0,0}//unsigned char unused[5]; // !
+       {32, 32, 32},//unsigned char glowmod[3];
 };
 
 // LordHavoc: I own protocol ranges 96, 97, 3500-3599
@@ -165,7 +164,7 @@ void EntityFrameQuake_ReadEntity(int bits)
        else
        {
                s = ent->state_baseline;
-               s.active = true;
+               s.active = ACTIVE_NETWORK;
        }
 
        cl.isquakeentity[num] = true;
@@ -226,7 +225,7 @@ void EntityFrameQuake_ReadEntity(int bits)
 
        ent->state_previous = ent->state_current;
        ent->state_current = s;
-       if (ent->state_current.active)
+       if (ent->state_current.active == ACTIVE_NETWORK)
        {
                CL_MoveLerpEntityStates(ent);
                cl.entities_active[ent->state_current.number] = true;
@@ -255,7 +254,7 @@ void EntityFrameQuake_ISeeDeadEntities(void)
                        else
                        {
                                cl.isquakeentity[num] = false;
-                               cl.entities_active[num] = false;
+                               cl.entities_active[num] = ACTIVE_NOT;
                                cl.entities[num].state_current = defaultstate;
                                cl.entities[num].state_current.number = num;
                        }
@@ -301,7 +300,7 @@ void EntityFrameCSQC_LostFrame(client_t *client, int framenum)
        int i, j, n;
        qboolean valid;
        int ringfirst, ringlast;
-       int recoversendflags[MAX_EDICTS];
+       static int recoversendflags[MAX_EDICTS];
        csqcentityframedb_t *d;
 
        n = client->csqcnumedicts;
@@ -430,11 +429,11 @@ static void EntityFrameCSQC_DeallocFrame(client_t *client, int framenum)
 //[515]: we use only one array per-client for SendEntity feature
 // TODO: add some handling for entity send priorities, to better deal with huge
 // amounts of csqc networked entities
-qboolean EntityFrameCSQC_WriteFrame (sizebuf_t *msg, int maxsize, int numstates, const entity_state_t *states, int framenum)
+qboolean EntityFrameCSQC_WriteFrame (sizebuf_t *msg, int maxsize, int numnumbers, const unsigned short *numbers, int framenum)
 {
        int num, number, end, sendflags;
        qboolean sectionstarted = false;
-       const entity_state_t *n;
+       const unsigned short *n;
        prvm_edict_t *ed;
        prvm_eval_t *val;
        client_t *client = svs.clients + sv.writeentitiestoclient_clientnumber;
@@ -456,9 +455,9 @@ qboolean EntityFrameCSQC_WriteFrame (sizebuf_t *msg, int maxsize, int numstates,
                client->csqcnumedicts = prog->num_edicts;
 
        number = 1;
-       for (num = 0, n = states;num < numstates;num++, n++)
+       for (num = 0, n = numbers;num < numnumbers;num++, n++)
        {
-               end = n->number;
+               end = *n;
                for (;number < end;number++)
                {
                        if (client->csqcentityscope[number])
@@ -494,9 +493,9 @@ qboolean EntityFrameCSQC_WriteFrame (sizebuf_t *msg, int maxsize, int numstates,
                if (client->csqcentityscope[number])
                        client->csqcentityscope[number] = 1;
        // keep visible entities
-       for (i = 0, n = states;i < numstates;i++, n++)
+       for (i = 0, n = numbers;i < numnumbers;i++, n++)
        {
-               number = n->number;
+               number = *n;
                ed = prog->edicts + number;
                val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.SendEntity);
                if (val->function)
@@ -680,7 +679,7 @@ void Protocol_WriteStatsReliable(void)
 }
 
 
-void EntityFrameQuake_WriteFrame(sizebuf_t *msg, int maxsize, int numstates, const entity_state_t *states)
+qboolean EntityFrameQuake_WriteFrame(sizebuf_t *msg, int maxsize, int numstates, const entity_state_t **states)
 {
        const entity_state_t *s;
        entity_state_t baseline;
@@ -688,15 +687,17 @@ void EntityFrameQuake_WriteFrame(sizebuf_t *msg, int maxsize, int numstates, con
        sizebuf_t buf;
        unsigned char data[128];
        prvm_eval_t *val;
+       qboolean success = false;
 
        // prepare the buffer
        memset(&buf, 0, sizeof(buf));
        buf.data = data;
        buf.maxsize = sizeof(data);
 
-       for (i = 0, s = states;i < numstates;i++, s++)
+       for (i = 0;i < numstates;i++)
        {
-               ENTITYSIZEPROFILING_START(msg, s->number);
+               ENTITYSIZEPROFILING_START(msg, states[i]->number);
+               s = states[i];
                val = PRVM_EDICTFIELDVALUE((&prog->edicts[s->number]), prog->fieldoffsets.SendEntity);
                if(val && val->function)
                        continue;
@@ -840,15 +841,17 @@ void EntityFrameQuake_WriteFrame(sizebuf_t *msg, int maxsize, int numstates, con
                }
                // write the message to the packet
                SZ_Write(msg, buf.data, buf.cursize);
+               success = true;
                ENTITYSIZEPROFILING_END(msg, s->number);
        }
+       return success;
 }
 
 int EntityState_DeltaBits(const entity_state_t *o, const entity_state_t *n)
 {
        unsigned int bits;
        // if o is not active, delta from default
-       if (!o->active)
+       if (o->active != ACTIVE_NETWORK)
                o = &defaultstate;
        bits = 0;
        if (fabs(n->origin[0] - o->origin[0]) > (1.0f / 256.0f))
@@ -1027,7 +1030,7 @@ void EntityState_WriteUpdate(const entity_state_t *ent, sizebuf_t *msg, const en
 {
        unsigned int bits;
        ENTITYSIZEPROFILING_START(msg, ent->number);
-       if (ent->active)
+       if (ent->active == ACTIVE_NETWORK)
        {
                // entity is active, check for changes from the delta
                if ((bits = EntityState_DeltaBits(delta, ent)))
@@ -1041,7 +1044,7 @@ void EntityState_WriteUpdate(const entity_state_t *ent, sizebuf_t *msg, const en
        else
        {
                // entity is inactive, check if the delta was active
-               if (delta->active)
+               if (delta->active == ACTIVE_NETWORK)
                {
                        // write the remove number
                        MSG_WriteShort(msg, ent->number | 0x8000);
@@ -1213,6 +1216,8 @@ void EntityState_ReadFields(entity_state_t *e, unsigned int bits)
        }
 }
 
+extern void CL_NewFrameReceived(int num);
+
 // (client and server) allocates a new empty database
 entityframe_database_t *EntityFrame_AllocDatabase(mempool_t *mempool)
 {
@@ -1278,8 +1283,60 @@ void EntityFrame_FetchFrame(entityframe_database_t *d, int framenum, entity_fram
        }
 }
 
-// (server and client) adds a entity_frame to the database, for future reference
-void EntityFrame_AddFrame(entityframe_database_t *d, vec3_t eye, int framenum, int numentities, const entity_state_t *entitydata)
+// (client) adds a entity_frame to the database, for future reference
+void EntityFrame_AddFrame_Client(entityframe_database_t *d, vec3_t eye, int framenum, int numentities, const entity_state_t *entitydata)
+{
+       int n, e;
+       entity_frameinfo_t *info;
+
+       VectorCopy(eye, d->eye);
+
+       // figure out how many entity slots are used already
+       if (d->numframes)
+       {
+               n = d->frames[d->numframes - 1].endentity - d->frames[0].firstentity;
+               if (n + numentities > MAX_ENTITY_DATABASE || d->numframes >= MAX_ENTITY_HISTORY)
+               {
+                       // ran out of room, dump database
+                       EntityFrame_ClearDatabase(d);
+               }
+       }
+
+       info = &d->frames[d->numframes];
+       info->framenum = framenum;
+       e = -1000;
+       // make sure we check the newly added frame as well, but we haven't incremented numframes yet
+       for (n = 0;n <= d->numframes;n++)
+       {
+               if (e >= d->frames[n].framenum)
+               {
+                       if (e == framenum)
+                               Con_Print("EntityFrame_AddFrame: tried to add out of sequence frame to database\n");
+                       else
+                               Con_Print("EntityFrame_AddFrame: out of sequence frames in database\n");
+                       return;
+               }
+               e = d->frames[n].framenum;
+       }
+       // if database still has frames after that...
+       if (d->numframes)
+               info->firstentity = d->frames[d->numframes - 1].endentity;
+       else
+               info->firstentity = 0;
+       info->endentity = info->firstentity + numentities;
+       d->numframes++;
+
+       n = info->firstentity % MAX_ENTITY_DATABASE;
+       e = MAX_ENTITY_DATABASE - n;
+       if (e > numentities)
+               e = numentities;
+       memcpy(d->entitydata + n, entitydata, sizeof(entity_state_t) * e);
+       if (numentities > e)
+               memcpy(d->entitydata, entitydata + e, sizeof(entity_state_t) * (numentities - e));
+}
+
+// (server) adds a entity_frame to the database, for future reference
+void EntityFrame_AddFrame_Server(entityframe_database_t *d, vec3_t eye, int framenum, int numentities, const entity_state_t **entitydata)
 {
        int n, e;
        entity_frameinfo_t *info;
@@ -1331,7 +1388,7 @@ void EntityFrame_AddFrame(entityframe_database_t *d, vec3_t eye, int framenum, i
 }
 
 // (server) writes a frame to network stream
-void EntityFrame_WriteFrame(sizebuf_t *msg, int maxsize, entityframe_database_t *d, int numstates, const entity_state_t *states, int viewentnum)
+qboolean EntityFrame_WriteFrame(sizebuf_t *msg, int maxsize, entityframe_database_t *d, int numstates, const entity_state_t **states, int viewentnum)
 {
        int i, onum, number;
        entity_frame_t *o = &d->deltaframe;
@@ -1344,14 +1401,15 @@ void EntityFrame_WriteFrame(sizebuf_t *msg, int maxsize, entityframe_database_t
        VectorClear(eye);
        for (i = 0;i < numstates;i++)
        {
-               if (states[i].number == viewentnum)
+               ent = states[i];
+               if (ent->number == viewentnum)
                {
-                       VectorSet(eye, states[i].origin[0], states[i].origin[1], states[i].origin[2] + 22);
+                       VectorSet(eye, ent->origin[0], ent->origin[1], ent->origin[2] + 22);
                        break;
                }
        }
 
-       EntityFrame_AddFrame(d, eye, d->latestframenum, numstates, states);
+       EntityFrame_AddFrame_Server(d, eye, d->latestframenum, numstates, states);
 
        EntityFrame_FetchFrame(d, d->ackframenum, o);
 
@@ -1365,12 +1423,12 @@ void EntityFrame_WriteFrame(sizebuf_t *msg, int maxsize, entityframe_database_t
        onum = 0;
        for (i = 0;i < numstates;i++)
        {
-               ent = states + i;
+               ent = states[i];
                number = ent->number;
 
                val = PRVM_EDICTFIELDVALUE((&prog->edicts[number]), prog->fieldoffsets.SendEntity);
                if(val && val->function)
-                               continue;
+                       continue;
                for (;onum < o->numentities && o->entitydata[onum].number < number;onum++)
                {
                        // write remove message
@@ -1396,6 +1454,8 @@ void EntityFrame_WriteFrame(sizebuf_t *msg, int maxsize, entityframe_database_t
                MSG_WriteShort(msg, o->entitydata[onum].number | 0x8000);
        }
        MSG_WriteShort(msg, 0xFFFF);
+
+       return true;
 }
 
 // (client) reads a frame from network stream
@@ -1417,9 +1477,8 @@ void EntityFrame_CL_ReadFrame(void)
        // read the frame header info
        f->time = cl.mtime[0];
        number = MSG_ReadLong();
-       for (i = 0;i < LATESTFRAMENUMS-1;i++)
-               cl.latestframenums[i] = cl.latestframenums[i+1];
-       cl.latestframenums[LATESTFRAMENUMS-1] = f->framenum = MSG_ReadLong();
+       f->framenum = MSG_ReadLong();
+       CL_NewFrameReceived(f->framenum);
        f->eye[0] = MSG_ReadFloat();
        f->eye[1] = MSG_ReadFloat();
        f->eye[2] = MSG_ReadFloat();
@@ -1478,7 +1537,7 @@ void EntityFrame_CL_ReadFrame(void)
                                        CL_ExpandEntities(number);
                        }
                        cl.entities_active[number] = true;
-                       e->active = true;
+                       e->active = ACTIVE_NETWORK;
                        e->time = cl.mtime[0];
                        e->number = number;
                        EntityState_ReadFields(e, EntityState_ReadExtendBits());
@@ -1491,7 +1550,7 @@ void EntityFrame_CL_ReadFrame(void)
                f->entitydata[f->numentities] = *old++;
                f->entitydata[f->numentities++].time = cl.mtime[0];
        }
-       EntityFrame_AddFrame(d, f->eye, f->framenum, f->numentities, f->entitydata);
+       EntityFrame_AddFrame_Client(d, f->eye, f->framenum, f->numentities, f->entitydata);
 
        memset(cl.entities_active, 0, cl.num_entities * sizeof(unsigned char));
        number = 1;
@@ -1502,7 +1561,7 @@ void EntityFrame_CL_ReadFrame(void)
                        if (cl.entities_active[number])
                        {
                                cl.entities_active[number] = false;
-                               cl.entities[number].state_current.active = false;
+                               cl.entities[number].state_current.active = ACTIVE_NOT;
                        }
                }
                if (number >= cl.num_entities)
@@ -1521,7 +1580,7 @@ void EntityFrame_CL_ReadFrame(void)
                if (cl.entities_active[number])
                {
                        cl.entities_active[number] = false;
-                       cl.entities[number].state_current.active = false;
+                       cl.entities[number].state_current.active = ACTIVE_NOT;
                }
        }
 }
@@ -1646,7 +1705,7 @@ int EntityFrame4_AckFrame(entityframe4_database_t *d, int framenum, int servermo
                                                        entity_state_t *s = EntityFrame4_GetReferenceEntity(d, commit->entity[j].number);
                                                        if (commit->entity[j].active != s->active)
                                                        {
-                                                               if (commit->entity[j].active)
+                                                               if (commit->entity[j].active == ACTIVE_NETWORK)
                                                                        Con_Printf("commit entity %i has become active (modelindex %i)\n", commit->entity[j].number, commit->entity[j].modelindex);
                                                                else
                                                                        Con_Printf("commit entity %i has become inactive (modelindex %i)\n", commit->entity[j].number, commit->entity[j].modelindex);
@@ -1684,9 +1743,8 @@ void EntityFrame4_CL_ReadFrame(void)
        // read the number of the frame this refers to
        referenceframenum = MSG_ReadLong();
        // read the number of this frame
-       for (i = 0;i < LATESTFRAMENUMS-1;i++)
-               cl.latestframenums[i] = cl.latestframenums[i+1];
-       cl.latestframenums[LATESTFRAMENUMS-1] = framenum = MSG_ReadLong();
+       framenum = MSG_ReadLong();
+       CL_NewFrameReceived(framenum);
        // read the start number
        enumber = (unsigned short) MSG_ReadShort();
        if (developer_networkentities.integer >= 10)
@@ -1774,20 +1832,20 @@ void EntityFrame4_CL_ReadFrame(void)
                                        // read the changes
                                        if (developer_networkentities.integer >= 2)
                                                Con_Printf("entity %i: update\n", enumber);
-                                       s->active = true;
+                                       s->active = ACTIVE_NETWORK;
                                        EntityState_ReadFields(s, EntityState_ReadExtendBits());
                                }
                        }
                        else if (developer_networkentities.integer >= 4)
                                Con_Printf("entity %i: copy\n", enumber);
                        // set the cl.entities_active flag
-                       cl.entities_active[enumber] = s->active;
+                       cl.entities_active[enumber] = (s->active == ACTIVE_NETWORK);
                        // set the update time
                        s->time = cl.mtime[0];
                        // fix the number (it gets wiped occasionally by copying from defaultstate)
                        s->number = enumber;
                        // check if we need to update the lerp stuff
-                       if (s->active)
+                       if (s->active == ACTIVE_NETWORK)
                                CL_MoveLerpEntityStates(&cl.entities[enumber]);
                        // add this to the commit entry whether it is modified or not
                        if (d->currentcommit)
@@ -1795,7 +1853,7 @@ void EntityFrame4_CL_ReadFrame(void)
                        // print extra messages if desired
                        if (developer_networkentities.integer >= 2 && cl.entities[enumber].state_current.active != cl.entities[enumber].state_previous.active)
                        {
-                               if (cl.entities[enumber].state_current.active)
+                               if (cl.entities[enumber].state_current.active == ACTIVE_NETWORK)
                                        Con_Printf("entity #%i has become active\n", enumber);
                                else if (cl.entities[enumber].state_previous.active)
                                        Con_Printf("entity #%i has become inactive\n", enumber);
@@ -1807,7 +1865,7 @@ void EntityFrame4_CL_ReadFrame(void)
                EntityFrame4_ResetDatabase(d);
 }
 
-void EntityFrame4_WriteFrame(sizebuf_t *msg, int maxsize, entityframe4_database_t *d, int numstates, const entity_state_t *states)
+qboolean EntityFrame4_WriteFrame(sizebuf_t *msg, int maxsize, entityframe4_database_t *d, int numstates, const entity_state_t **states)
 {
        const entity_state_t *e, *s;
        entity_state_t inactiveentitystate;
@@ -1818,7 +1876,7 @@ void EntityFrame4_WriteFrame(sizebuf_t *msg, int maxsize, entityframe4_database_
 
        // if there isn't enough space to accomplish anything, skip it
        if (msg->cursize + 24 > maxsize)
-               return;
+               return false;
 
        // prepare the buffer
        memset(&buf, 0, sizeof(buf));
@@ -1830,7 +1888,7 @@ void EntityFrame4_WriteFrame(sizebuf_t *msg, int maxsize, entityframe4_database_
                        break;
        // if commit buffer full, just don't bother writing an update this frame
        if (i == MAX_ENTITY_HISTORY)
-               return;
+               return false;
        d->currentcommit = d->commit + i;
 
        // this state's number gets played around with later
@@ -1868,9 +1926,9 @@ void EntityFrame4_WriteFrame(sizebuf_t *msg, int maxsize, entityframe4_database_
                SZ_Clear(&buf);
                // entity exists, build an update (if empty there is no change)
                // find the state in the list
-               for (;i < numstates && states[i].number < n;i++);
+               for (;i < numstates && states[i]->number < n;i++);
                // make the message
-               s = states + i;
+               s = states[i];
                if (s->number == n)
                {
                        // build the update
@@ -1880,7 +1938,7 @@ void EntityFrame4_WriteFrame(sizebuf_t *msg, int maxsize, entityframe4_database_
                {
                        inactiveentitystate.number = n;
                        s = &inactiveentitystate;
-                       if (e->active)
+                       if (e->active == ACTIVE_NETWORK)
                        {
                                // entity used to exist but doesn't anymore, send remove
                                MSG_WriteShort(&buf, n | 0x8000);
@@ -1909,6 +1967,8 @@ void EntityFrame4_WriteFrame(sizebuf_t *msg, int maxsize, entityframe4_database_
        MSG_WriteShort(msg, d->currententitynumber);
        // just to be sure
        d->currentcommit = NULL;
+
+       return true;
 }
 
 
@@ -1978,7 +2038,7 @@ static int EntityState5_Priority(entityframe5_database_t *d, int stateindex)
        if (stateindex <= svs.maxclients)
                priority++;
        // remove dead entities very quickly because they are just 2 bytes
-       if (!d->states[stateindex].active)
+       if (d->states[stateindex].active != ACTIVE_NETWORK)
        {
                priority++;
                return bound(1, priority, ENTITYFRAME5_PRIORITYLEVELS - 1);
@@ -2019,13 +2079,13 @@ void EntityState5_WriteUpdate(int number, const entity_state_t *s, int changedbi
        if(val && val->function)
                return;
 
-       if (!s->active)
+       if (s->active != ACTIVE_NETWORK)
                MSG_WriteShort(msg, number | 0x8000);
        else
        {
                bits = changedbits;
-               if ((bits & E5_ORIGIN) && (s->exteriormodelforclient || s->tagentity || s->viewmodelforclient || (s->number >= 1 && s->number <= svs.maxclients) || s->origin[0] <= -4096.0625 || s->origin[0] >= 4095.9375 || s->origin[1] <= -4096.0625 || s->origin[1] >= 4095.9375 || s->origin[2] <= -4096.0625 || s->origin[2] >= 4095.9375))
-               // maybe also add: ((model = sv.models[s->modelindex]) != NULL && model->name[0] == '*')
+               if ((bits & E5_ORIGIN) && (!(s->flags & RENDER_LOWPRECISION) || s->exteriormodelforclient || s->tagentity || s->viewmodelforclient || (s->number >= 1 && s->number <= svs.maxclients) || s->origin[0] <= -4096.0625 || s->origin[0] >= 4095.9375 || s->origin[1] <= -4096.0625 || s->origin[1] >= 4095.9375 || s->origin[2] <= -4096.0625 || s->origin[2] >= 4095.9375))
+               // maybe also add: ((model = SV_GetModelByIndex(s->modelindex)) != NULL && model->name[0] == '*')
                        bits |= E5_ORIGIN32;
                        // possible values:
                        //   negative origin:
@@ -2151,6 +2211,12 @@ void EntityState5_WriteUpdate(int number, const entity_state_t *s, int changedbi
                        MSG_WriteByte(msg, s->colormod[1]);
                        MSG_WriteByte(msg, s->colormod[2]);
                }
+               if (bits & E5_GLOWMOD)
+               {
+                       MSG_WriteByte(msg, s->glowmod[0]);
+                       MSG_WriteByte(msg, s->glowmod[1]);
+                       MSG_WriteByte(msg, s->glowmod[2]);
+               }
        }
 
        ENTITYSIZEPROFILING_END(msg, s->number);
@@ -2173,7 +2239,7 @@ static void EntityState5_ReadUpdate(entity_state_t *s, int number)
        if (bits & E5_FULLUPDATE)
        {
                *s = defaultstate;
-               s->active = true;
+               s->active = ACTIVE_NETWORK;
        }
        if (bits & E5_FLAGS)
                s->flags = MSG_ReadByte();
@@ -2263,6 +2329,12 @@ static void EntityState5_ReadUpdate(entity_state_t *s, int number)
                s->colormod[1] = MSG_ReadByte();
                s->colormod[2] = MSG_ReadByte();
        }
+       if (bits & E5_GLOWMOD)
+       {
+               s->glowmod[0] = MSG_ReadByte();
+               s->glowmod[1] = MSG_ReadByte();
+               s->glowmod[2] = MSG_ReadByte();
+       }
 
 
        if (developer_networkentities.integer >= 2)
@@ -2318,6 +2390,8 @@ static void EntityState5_ReadUpdate(entity_state_t *s, int number)
                        Con_Printf(" E5_GLOW %i:%i", s->glowsize * 4, s->glowcolor);
                if (bits & E5_COLORMOD)
                        Con_Printf(" E5_COLORMOD %f:%f:%f", s->colormod[0] / 32.0f, s->colormod[1] / 32.0f, s->colormod[2] / 32.0f);
+               if (bits & E5_GLOWMOD)
+                       Con_Printf(" E5_GLOWMOD %f:%f:%f", s->glowmod[0] / 32.0f, s->glowmod[1] / 32.0f, s->glowmod[2] / 32.0f);
                Con_Print("\n");
        }
 }
@@ -2325,9 +2399,9 @@ static void EntityState5_ReadUpdate(entity_state_t *s, int number)
 static int EntityState5_DeltaBits(const entity_state_t *o, const entity_state_t *n)
 {
        unsigned int bits = 0;
-       if (n->active)
+       if (n->active == ACTIVE_NETWORK)
        {
-               if (!o->active)
+               if (o->active != ACTIVE_NETWORK)
                        bits |= E5_FULLUPDATE;
                if (!VectorCompare(o->origin, n->origin))
                        bits |= E5_ORIGIN;
@@ -2357,24 +2431,23 @@ static int EntityState5_DeltaBits(const entity_state_t *o, const entity_state_t
                        bits |= E5_GLOW;
                if (o->colormod[0] != n->colormod[0] || o->colormod[1] != n->colormod[1] || o->colormod[2] != n->colormod[2])
                        bits |= E5_COLORMOD;
+               if (o->glowmod[0] != n->glowmod[0] || o->glowmod[1] != n->glowmod[1] || o->glowmod[2] != n->glowmod[2])
+                       bits |= E5_GLOWMOD;
        }
        else
-               if (o->active)
+               if (o->active == ACTIVE_NETWORK)
                        bits |= E5_FULLUPDATE;
        return bits;
 }
 
 void EntityFrame5_CL_ReadFrame(void)
 {
-       int i, n, enumber;
+       int n, enumber, framenum;
        entity_t *ent;
        entity_state_t *s;
        // read the number of this frame to echo back in next input packet
-       for (i = 0;i < LATESTFRAMENUMS-1;i++)
-               cl.latestframenums[i] = cl.latestframenums[i+1];
-       cl.latestframenums[LATESTFRAMENUMS-1] = MSG_ReadLong();
-       if (developer_networkentities.integer >= 10)
-               Con_Printf("recv: svc_entities %i\n", cl.latestframenums[LATESTFRAMENUMS-1]);
+       framenum = MSG_ReadLong();
+       CL_NewFrameReceived(framenum);
        if (cls.protocol != PROTOCOL_QUAKE && cls.protocol != PROTOCOL_QUAKEDP && cls.protocol != PROTOCOL_NEHAHRAMOVIE && cls.protocol != PROTOCOL_DARKPLACES1 && cls.protocol != PROTOCOL_DARKPLACES2 && cls.protocol != PROTOCOL_DARKPLACES3 && cls.protocol != PROTOCOL_DARKPLACES4 && cls.protocol != PROTOCOL_DARKPLACES5 && cls.protocol != PROTOCOL_DARKPLACES6)
                cls.servermovesequence = MSG_ReadLong();
        // read entity numbers until we find a 0x8000
@@ -2407,18 +2480,18 @@ void EntityFrame5_CL_ReadFrame(void)
                        EntityState5_ReadUpdate(s, enumber);
                }
                // set the cl.entities_active flag
-               cl.entities_active[enumber] = s->active;
+               cl.entities_active[enumber] = (s->active == ACTIVE_NETWORK);
                // set the update time
                s->time = cl.mtime[0];
                // fix the number (it gets wiped occasionally by copying from defaultstate)
                s->number = enumber;
                // check if we need to update the lerp stuff
-               if (s->active)
+               if (s->active == ACTIVE_NETWORK)
                        CL_MoveLerpEntityStates(&cl.entities[enumber]);
                // print extra messages if desired
                if (developer_networkentities.integer >= 2 && cl.entities[enumber].state_current.active != cl.entities[enumber].state_previous.active)
                {
-                       if (cl.entities[enumber].state_current.active)
+                       if (cl.entities[enumber].state_current.active == ACTIVE_NETWORK)
                                Con_Printf("entity #%i has become active\n", enumber);
                        else if (cl.entities[enumber].state_previous.active)
                                Con_Printf("entity #%i has become inactive\n", enumber);
@@ -2499,7 +2572,7 @@ void EntityFrame5_AckFrame(entityframe5_database_t *d, int framenum)
                        d->packetlog[i].packetnumber = 0;
 }
 
-void EntityFrame5_WriteFrame(sizebuf_t *msg, int maxsize, entityframe5_database_t *d, int numstates, const entity_state_t *states, int viewentnum, int movesequence, qboolean need_empty)
+qboolean EntityFrame5_WriteFrame(sizebuf_t *msg, int maxsize, entityframe5_database_t *d, int numstates, const entity_state_t **states, int viewentnum, int movesequence, qboolean need_empty)
 {
        const entity_state_t *n;
        int i, num, l, framenum, packetlognumber, priority;
@@ -2532,8 +2605,9 @@ void EntityFrame5_WriteFrame(sizebuf_t *msg, int maxsize, entityframe5_database_
 
        // detect changes in states
        num = 1;
-       for (i = 0, n = states;i < numstates;i++, n++)
+       for (i = 0;i < numstates;i++)
        {
+               n = states[i];
                // mark gaps in entity numbering as removed entities
                for (;num < n->number;num++)
                {
@@ -2581,7 +2655,7 @@ void EntityFrame5_WriteFrame(sizebuf_t *msg, int maxsize, entityframe5_database_
        // if there isn't at least enough room for an empty svc_entities,
        // don't bother trying...
        if (buf.cursize + 11 > buf.maxsize)
-               return;
+               return false;
 
        // build lists of entities by priority level
        memset(d->prioritychaincounts, 0, sizeof(d->prioritychaincounts));
@@ -2641,7 +2715,7 @@ void EntityFrame5_WriteFrame(sizebuf_t *msg, int maxsize, entityframe5_database_
 
        // only send empty svc_entities frame if needed
        if(!l && !need_empty)
-               return;
+               return false;
 
        // add packetlog entry now that we have something for it
        if (!packetlog)
@@ -2686,6 +2760,8 @@ void EntityFrame5_WriteFrame(sizebuf_t *msg, int maxsize, entityframe5_database_
                }
        }
        MSG_WriteShort(msg, 0x8000);
+
+       return true;
 }
 
 
@@ -2748,7 +2824,7 @@ void EntityStateQW_ReadPlayerUpdate(void)
        // read the update
        s = &ent->state_current;
        *s = defaultstate;
-       s->active = true;
+       s->active = ACTIVE_NETWORK;
        s->number = enumber;
        s->colormap = enumber;
        playerflags = MSG_ReadShort();
@@ -2851,18 +2927,18 @@ void EntityStateQW_ReadPlayerUpdate(void)
        }
 
        // set the cl.entities_active flag
-       cl.entities_active[enumber] = s->active;
+       cl.entities_active[enumber] = (s->active == ACTIVE_NETWORK);
        // set the update time
        s->time = cl.mtime[0] - msec * 0.001; // qw has no clock
        // check if we need to update the lerp stuff
-       if (s->active)
+       if (s->active == ACTIVE_NETWORK)
                CL_MoveLerpEntityStates(&cl.entities[enumber]);
 }
 
 static void EntityStateQW_ReadEntityUpdate(entity_state_t *s, int bits)
 {
        int qweffects = 0;
-       s->active = true;
+       s->active = ACTIVE_NETWORK;
        s->number = bits & 511;
        bits &= ~511;
        if (bits & QW_U_MOREBITS)
@@ -3062,7 +3138,7 @@ void EntityFrameQW_CL_ReadFrame(qboolean delta)
                        if (cl.entities_active[number])
                        {
                                cl.entities_active[number] = false;
-                               cl.entities[number].state_current.active = false;
+                               cl.entities[number].state_current.active = ACTIVE_NOT;
                        }
                }
                if (number >= cl.num_entities)