]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - protocol.c
hush reconnect command warning about signon 0 because it happens all the time
[xonotic/darkplaces.git] / protocol.c
index 0fe0cc0e9528b503535abae03bbcf55b4f7b29ef..f22241e706d48c9474d67c1065fefef99be850f6 100644 (file)
@@ -35,7 +35,9 @@ entity_state_t defaultstate =
        {0,0,0,0}//unsigned char unused[4]; // !
 };
 
-double entityframequake_mtime = 0;
+// keep track of quake entities because they need to be killed if they get stale
+int cl_lastquakeentity = 0;
+qbyte cl_isquakeentity[MAX_EDICTS];
 
 void EntityFrameQuake_ReadEntity(int bits)
 {
@@ -43,8 +45,6 @@ void EntityFrameQuake_ReadEntity(int bits)
        entity_t *ent;
        entity_state_t s;
 
-       entityframequake_mtime = cl.mtime[0];
-
        if (bits & U_MOREBITS)
                bits |= (MSG_ReadByte()<<8);
        if ((bits & U_EXTEND1) && cl.protocol != PROTOCOL_NEHAHRAMOVIE)
@@ -77,6 +77,9 @@ void EntityFrameQuake_ReadEntity(int bits)
                s.active = true;
        }
 
+       cl_isquakeentity[num] = true;
+       if (cl_lastquakeentity < num)
+               cl_lastquakeentity = num;
        s.number = num;
        s.time = cl.mtime[0];
        s.flags = 0;
@@ -85,12 +88,12 @@ void EntityFrameQuake_ReadEntity(int bits)
        if (bits & U_COLORMAP)  s.colormap = MSG_ReadByte();
        if (bits & U_SKIN)              s.skin = MSG_ReadByte();
        if (bits & U_EFFECTS)   s.effects = (s.effects & 0xFF00) | MSG_ReadByte();
-       if (bits & U_ORIGIN1)   s.origin[0] = MSG_ReadCoord13i();
-       if (bits & U_ANGLE1)    s.angles[0] = MSG_ReadAngle8i();
-       if (bits & U_ORIGIN2)   s.origin[1] = MSG_ReadCoord13i();
-       if (bits & U_ANGLE2)    s.angles[1] = MSG_ReadAngle8i();
-       if (bits & U_ORIGIN3)   s.origin[2] = MSG_ReadCoord13i();
-       if (bits & U_ANGLE3)    s.angles[2] = MSG_ReadAngle8i();
+       if (bits & U_ORIGIN1)   s.origin[0] = MSG_ReadCoord(cl.protocol);
+       if (bits & U_ANGLE1)    s.angles[0] = MSG_ReadAngle(cl.protocol);
+       if (bits & U_ORIGIN2)   s.origin[1] = MSG_ReadCoord(cl.protocol);
+       if (bits & U_ANGLE2)    s.angles[1] = MSG_ReadAngle(cl.protocol);
+       if (bits & U_ORIGIN3)   s.origin[2] = MSG_ReadCoord(cl.protocol);
+       if (bits & U_ANGLE3)    s.angles[2] = MSG_ReadAngle(cl.protocol);
        if (bits & U_STEP)              s.flags |= RENDER_STEP;
        if (bits & U_ALPHA)             s.alpha = MSG_ReadByte();
        if (bits & U_SCALE)             s.scale = MSG_ReadByte();
@@ -138,14 +141,27 @@ void EntityFrameQuake_ReadEntity(int bits)
 
 void EntityFrameQuake_ISeeDeadEntities(void)
 {
-       int i;
-       for (i = 0;i < cl_max_entities;i++)
+       int num, lastentity;
+       if (cl_lastquakeentity == 0)
+               return;
+       lastentity = cl_lastquakeentity;
+       cl_lastquakeentity = 0;
+       for (num = 0;num <= lastentity;num++)
        {
-               if (cl_entities_active[i] && cl_entities[i].state_current.time != cl.mtime[0])
+               if (cl_isquakeentity[num])
                {
-                       cl_entities_active[i] = false;
-                       cl_entities[i].state_current = defaultstate;
-                       cl_entities[i].state_current.number = i;
+                       if (cl_entities_active[num] && cl_entities[num].state_current.time == cl.mtime[0])
+                       {
+                               cl_isquakeentity[num] = true;
+                               cl_lastquakeentity = num;
+                       }
+                       else
+                       {
+                               cl_isquakeentity[num] = false;
+                               cl_entities_active[num] = false;
+                               cl_entities[num].state_current = defaultstate;
+                               cl_entities[num].state_current.number = num;
+                       }
                }
        }
 }
@@ -251,12 +267,12 @@ void EntityFrameQuake_WriteFrame(sizebuf_t *msg, int numstates, const entity_sta
                if (bits & U_COLORMAP)          MSG_WriteByte(&buf, s->colormap);
                if (bits & U_SKIN)                      MSG_WriteByte(&buf, s->skin);
                if (bits & U_EFFECTS)           MSG_WriteByte(&buf, s->effects);
-               if (bits & U_ORIGIN1)           MSG_WriteCoord13i(&buf, s->origin[0]);
-               if (bits & U_ANGLE1)            MSG_WriteAngle8i(&buf, s->angles[0]);
-               if (bits & U_ORIGIN2)           MSG_WriteCoord13i(&buf, s->origin[1]);
-               if (bits & U_ANGLE2)            MSG_WriteAngle8i(&buf, s->angles[1]);
-               if (bits & U_ORIGIN3)           MSG_WriteCoord13i(&buf, s->origin[2]);
-               if (bits & U_ANGLE3)            MSG_WriteAngle8i(&buf, s->angles[2]);
+               if (bits & U_ORIGIN1)           MSG_WriteCoord(&buf, s->origin[0], sv.protocol);
+               if (bits & U_ANGLE1)            MSG_WriteAngle(&buf, s->angles[0], sv.protocol);
+               if (bits & U_ORIGIN2)           MSG_WriteCoord(&buf, s->origin[1], sv.protocol);
+               if (bits & U_ANGLE2)            MSG_WriteAngle(&buf, s->angles[1], sv.protocol);
+               if (bits & U_ORIGIN3)           MSG_WriteCoord(&buf, s->origin[2], sv.protocol);
+               if (bits & U_ANGLE3)            MSG_WriteAngle(&buf, s->angles[2], sv.protocol);
                if (bits & U_ALPHA)                     MSG_WriteByte(&buf, s->alpha);
                if (bits & U_SCALE)                     MSG_WriteByte(&buf, s->scale);
                if (bits & U_EFFECTS2)          MSG_WriteByte(&buf, s->effects >> 8);
@@ -666,8 +682,7 @@ void EntityFrame_ClearDatabase(entityframe_database_t *d)
 void EntityFrame_AckFrame(entityframe_database_t *d, int frame)
 {
        int i;
-       if (d->ackframenum < frame)
-               d->ackframenum = frame;
+       d->ackframenum = frame;
        for (i = 0;i < d->numframes && d->frames[i].framenum < frame;i++);
        // ignore outdated frame acks (out of order packets)
        if (i == 0)
@@ -785,7 +800,7 @@ void EntityFrame_WriteFrame(sizebuf_t *msg, entityframe_database_t *d, int numst
 
        EntityFrame_AddFrame(d, eye, d->latestframenum, numstates, states);
 
-       EntityFrame_FetchFrame(d, d->ackframenum > 0 ? d->ackframenum : -1, o);
+       EntityFrame_FetchFrame(d, d->ackframenum, o);
 
        MSG_WriteByte (msg, svc_entities);
        MSG_WriteLong (msg, o->framenum);
@@ -844,7 +859,7 @@ void EntityFrame_CL_ReadFrame(void)
        // read the frame header info
        f->time = cl.mtime[0];
        number = MSG_ReadLong();
-       f->framenum = MSG_ReadLong();
+       cl.latestframenum = f->framenum = MSG_ReadLong();
        f->eye[0] = MSG_ReadFloat();
        f->eye[1] = MSG_ReadFloat();
        f->eye[2] = MSG_ReadFloat();
@@ -1004,7 +1019,6 @@ entityframe4_database_t *EntityFrame4_AllocDatabase(mempool_t *pool)
        d = Mem_Alloc(pool, sizeof(*d));
        d->mempool = pool;
        EntityFrame4_ResetDatabase(d);
-       d->ackframenum = -1;
        return d;
 }
 
@@ -1022,7 +1036,6 @@ void EntityFrame4_FreeDatabase(entityframe4_database_t *d)
 void EntityFrame4_ResetDatabase(entityframe4_database_t *d)
 {
        int i;
-       d->ackframenum = -1;
        d->referenceframenum = -1;
        for (i = 0;i < MAX_ENTITY_HISTORY;i++)
                d->commit[i].numentities = 0;
@@ -1030,7 +1043,7 @@ void EntityFrame4_ResetDatabase(entityframe4_database_t *d)
                d->referenceentity[i] = defaultstate;
 }
 
-int EntityFrame4_AckFrame(entityframe4_database_t *d, int framenum)
+int EntityFrame4_AckFrame(entityframe4_database_t *d, int framenum, int servermode)
 {
        int i, j, found;
        entity_database4_commit_t *commit;
@@ -1040,6 +1053,9 @@ int EntityFrame4_AckFrame(entityframe4_database_t *d, int framenum)
                d->referenceframenum = -1;
                for (i = 0;i < d->maxreferenceentities;i++)
                        d->referenceentity[i] = defaultstate;
+               // if this is the server, remove commits
+                       for (i = 0, commit = d->commit;i < MAX_ENTITY_HISTORY;i++, commit++)
+                               commit->numentities = 0;
                found = true;
        }
        else if (d->referenceframenum == framenum)
@@ -1100,7 +1116,7 @@ void EntityFrame4_CL_ReadFrame(void)
        // read the number of the frame this refers to
        referenceframenum = MSG_ReadLong();
        // read the number of this frame
-       framenum = MSG_ReadLong();
+       cl.latestframenum = framenum = MSG_ReadLong();
        // read the start number
        enumber = (unsigned short) MSG_ReadShort();
        if (developer_networkentities.integer >= 1)
@@ -1111,7 +1127,7 @@ void EntityFrame4_CL_ReadFrame(void)
                                Con_Printf(" %i", d->commit[i].framenum);
                Con_Print("\n");
        }
-       if (!EntityFrame4_AckFrame(d, referenceframenum))
+       if (!EntityFrame4_AckFrame(d, referenceframenum, false))
        {
                Con_Print("EntityFrame4_CL_ReadFrame: reference frame invalid (VERY BAD ERROR), this update will be skipped\n");
                skip = true;
@@ -1122,7 +1138,7 @@ void EntityFrame4_CL_ReadFrame(void)
                if (!d->commit[i].numentities)
                {
                        d->currentcommit = d->commit + i;
-                       d->currentcommit->framenum = d->ackframenum = framenum;
+                       d->currentcommit->framenum = framenum;
                        d->currentcommit->numentities = 0;
                }
        }
@@ -1337,7 +1353,6 @@ void EntityFrame5_ResetDatabase(entityframe5_database_t *d)
        int i;
        memset(d, 0, sizeof(*d));
        d->latestframenum = 0;
-       d->ackframenum = -1;
        for (i = 0;i < MAX_EDICTS;i++)
                d->states[i] = defaultstate;
 }
@@ -1754,9 +1769,6 @@ void EntityFrame5_AckFrame(entityframe5_database_t *d, int framenum, int viewent
        int i, j, k, l, bits;
        entityframe5_changestate_t *s, *s2;
        entityframe5_packetlog_t *p, *p2;
-       if (framenum <= d->ackframenum)
-               return;
-       d->ackframenum = framenum;
        // scan for packets made obsolete by this ack
        for (i = 0, p = d->packetlog;i < ENTITYFRAME5_MAXPACKETLOGS;i++, p++)
        {