]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - protocol.c
added DP_SV_MODELFLAGS_AS_EFFECTS extension, this adds EF_ROCKET and
[xonotic/darkplaces.git] / protocol.c
index 9786497eaa9bfdcffe64daad05d9cd9105f9e43a..aa40970e1e18b8cf76f58693562ccc73c3adf3c7 100644 (file)
@@ -35,8 +35,9 @@ entity_state_t defaultstate =
        0,//unsigned char flags;
        0,//unsigned char tagindex;
        {32, 32, 32},//unsigned char colormod[3];
+       0,//unsigned char internaleffects; // INTEF_FLAG1QW and so on
        // padding to a multiple of 8 bytes (to align the double time)
-       {0,0}//unsigned char unused[2]; // !
+       0//unsigned char unused; // !
 };
 
 // LordHavoc: I own protocol ranges 96, 97, 3500-3599
@@ -419,6 +420,56 @@ void EntityFrameCSQC_WriteFrame (sizebuf_t *msg, int numstates, const entity_sta
        sv2csqcbuf = NULL;
 }
 
+void Protocol_UpdateClientStats(const int *stats)
+{
+       int i;
+       // update the stats array and set deltabits for any changed stats
+       for (i = 0;i < MAX_CL_STATS;i++)
+       {
+               if (host_client->stats[i] != stats[i])
+               {
+                       host_client->statsdeltabits[i >> 3] |= 1 << (i & 7);
+                       host_client->stats[i] = stats[i];
+               }
+       }
+}
+
+void Protocol_WriteStatsReliable(void)
+{
+       int i;
+       if (!host_client->netconnection)
+               return;
+       // detect changes in stats and write reliable messages
+       for (i = 0;i < MAX_CL_STATS;i++)
+       {
+               // quickly skip zero bytes
+               if (!host_client->statsdeltabits[i >> 3])
+               {
+                       i |= 7;
+                       continue;
+               }
+               // check if this bit is set
+               if (host_client->statsdeltabits[i >> 3] & (1 << (i & 7)))
+               {
+                       host_client->statsdeltabits[i >> 3] -= (1 << (i & 7));
+                       // send the stat as a byte if possible
+                       if (host_client->stats[i] >= 0 && host_client->stats[i] < 256)
+                       {
+                               MSG_WriteByte(&host_client->netconnection->message, svc_updatestatubyte);
+                               MSG_WriteByte(&host_client->netconnection->message, i);
+                               MSG_WriteByte(&host_client->netconnection->message, host_client->stats[i]);
+                       }
+                       else
+                       {
+                               MSG_WriteByte(&host_client->netconnection->message, svc_updatestat);
+                               MSG_WriteByte(&host_client->netconnection->message, i);
+                               MSG_WriteLong(&host_client->netconnection->message, host_client->stats[i]);
+                       }
+               }
+       }
+}
+
+
 void EntityFrameQuake_WriteFrame(sizebuf_t *msg, int numstates, const entity_state_t *states)
 {
        const entity_state_t *s;
@@ -1411,7 +1462,7 @@ void EntityFrame4_CL_ReadFrame(void)
        cl.latestframenums[LATESTFRAMENUMS-1] = framenum = MSG_ReadLong();
        // read the start number
        enumber = (unsigned short) MSG_ReadShort();
-       if (developer_networkentities.integer >= 1)
+       if (developer_networkentities.integer >= 10)
        {
                Con_Printf("recv svc_entities num:%i ref:%i database: ref:%i commits:", framenum, referenceframenum, d->referenceframenum);
                for (i = 0;i < MAX_ENTITY_HISTORY;i++)
@@ -1563,7 +1614,7 @@ void EntityFrame4_WriteFrame(sizebuf_t *msg, entityframe4_database_t *d, int num
        MSG_WriteByte(msg, svc_entities);
        MSG_WriteLong(msg, d->referenceframenum);
        MSG_WriteLong(msg, d->currentcommit->framenum);
-       if (developer_networkentities.integer >= 1)
+       if (developer_networkentities.integer >= 10)
        {
                Con_Printf("send svc_entities num:%i ref:%i (database: ref:%i commits:", d->currentcommit->framenum, d->referenceframenum, d->referenceframenum);
                for (i = 0;i < MAX_ENTITY_HISTORY;i++)
@@ -1744,7 +1795,7 @@ void EntityState5_WriteUpdate(int number, const entity_state_t *s, int changedbi
        else
        {
                bits = changedbits;
-               if ((bits & E5_ORIGIN) && (!(s->flags & RENDER_LOWPRECISION) || s->origin[0] < -4096 || s->origin[0] >= 4096 || s->origin[1] < -4096 || s->origin[1] >= 4096 || s->origin[2] < -4096 || s->origin[2] >= 4096))
+               if ((bits & E5_ORIGIN) && ((s->flags & RENDER_EXTERIORMODEL) || s->origin[0] < -4096 || s->origin[0] >= 4096 || s->origin[1] < -4096 || s->origin[1] >= 4096 || s->origin[2] < -4096 || s->origin[2] >= 4096))
                        bits |= E5_ORIGIN32;
                if ((bits & E5_ANGLES) && !(s->flags & RENDER_LOWPRECISION))
                        bits |= E5_ANGLES16;
@@ -1754,9 +1805,9 @@ void EntityState5_WriteUpdate(int number, const entity_state_t *s, int changedbi
                        bits |= E5_FRAME16;
                if (bits & E5_EFFECTS)
                {
-                       if (s->effects >= 65536)
+                       if (s->effects & 0xFFFF0000)
                                bits |= E5_EFFECTS32;
-                       else if (s->effects >= 256)
+                       else if (s->effects & 0xFFFFFF00)
                                bits |= E5_EFFECTS16;
                }
                if (bits >= 256)
@@ -1864,7 +1915,7 @@ void EntityState5_WriteUpdate(int number, const entity_state_t *s, int changedbi
        }
 }
 
-void EntityState5_ReadUpdate(entity_state_t *s)
+void EntityState5_ReadUpdate(entity_state_t *s, int number)
 {
        int bits;
        bits = MSG_ReadByte();
@@ -1975,7 +2026,7 @@ void EntityState5_ReadUpdate(entity_state_t *s)
 
        if (developer_networkentities.integer >= 2)
        {
-               Con_Printf("ReadFields e%i", s->number);
+               Con_Printf("ReadFields e%i", number);
 
                if (bits & E5_ORIGIN)
                        Con_Printf(" E5_ORIGIN %f %f %f", s->origin[0], s->origin[1], s->origin[2]);
@@ -2081,7 +2132,7 @@ void EntityFrame5_CL_ReadFrame(void)
        for (i = 0;i < LATESTFRAMENUMS-1;i++)
                cl.latestframenums[i] = cl.latestframenums[i+1];
        cl.latestframenums[LATESTFRAMENUMS-1] = MSG_ReadLong();
-       if (developer_networkentities.integer)
+       if (developer_networkentities.integer >= 10)
                Con_Printf("recv: svc_entities %i\n", cl.latestframenums[LATESTFRAMENUMS-1]);
        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();
@@ -2112,7 +2163,7 @@ void EntityFrame5_CL_ReadFrame(void)
                else
                {
                        // update entity
-                       EntityState5_ReadUpdate(s);
+                       EntityState5_ReadUpdate(s, enumber);
                }
                // set the cl.entities_active flag
                cl.entities_active[enumber] = s->active;
@@ -2184,13 +2235,13 @@ void EntityFrame5_LostFrame(entityframe5_database_t *d, int framenum)
                        for (j = 0;j < MAX_CL_STATS;j++)
                        {
                                for (l = 0;l < (MAX_CL_STATS+7)/8;l++)
-                                       statsdeltabits[l] = p->statsdeltabits[l] & ~d->statsdeltabits[l];
+                                       statsdeltabits[l] = p->statsdeltabits[l] & ~host_client->statsdeltabits[l];
                                for (k = 0, p2 = d->packetlog;k < ENTITYFRAME5_MAXPACKETLOGS;k++, p2++)
                                        if (p2->packetnumber > framenum)
                                                for (l = 0;l < (MAX_CL_STATS+7)/8;l++)
                                                        statsdeltabits[l] = p->statsdeltabits[l] & ~p2->statsdeltabits[l];
                                for (l = 0;l < (MAX_CL_STATS+7)/8;l++)
-                                       d->statsdeltabits[l] |= statsdeltabits[l];
+                                       host_client->statsdeltabits[l] |= statsdeltabits[l];
                        }
                        // delete this packet log as it is now obsolete
                        p->packetnumber = 0;
@@ -2207,7 +2258,7 @@ void EntityFrame5_AckFrame(entityframe5_database_t *d, int framenum)
                        d->packetlog[i].packetnumber = 0;
 }
 
-void EntityFrame5_WriteFrame(sizebuf_t *msg, entityframe5_database_t *d, int numstates, const entity_state_t *states, int viewentnum, int *stats, int movesequence)
+void EntityFrame5_WriteFrame(sizebuf_t *msg, entityframe5_database_t *d, int numstates, const entity_state_t *states, int viewentnum, int movesequence)
 {
        const entity_state_t *n;
        int i, num, l, framenum, packetlognumber, priority;
@@ -2238,16 +2289,6 @@ void EntityFrame5_WriteFrame(sizebuf_t *msg, entityframe5_database_t *d, int num
        buf.data = data;
        buf.maxsize = sizeof(data);
 
-       // detect changes in stats
-       for (i = 0;i < MAX_CL_STATS;i++)
-       {
-               if (d->stats[i] != stats[i])
-               {
-                       d->statsdeltabits[i>>3] |= (1<<(i&7));
-                       d->stats[i] = stats[i];
-               }
-       }
-
        // detect changes in states
        num = 1;
        for (i = 0, n = states;i < numstates;i++, n++)
@@ -2308,12 +2349,17 @@ void EntityFrame5_WriteFrame(sizebuf_t *msg, entityframe5_database_t *d, int num
        {
                if (d->priorities[num])
                {
-                       if (d->priorities[num] < (E5_PROTOCOL_PRIORITYLEVELS - 1))
-                               d->priorities[num] = EntityState5_Priority(d, num);
-                       l = num;
-                       priority = d->priorities[num];
-                       if (entityframe5_prioritychaincounts[priority] < ENTITYFRAME5_MAXSTATES)
-                               entityframe5_prioritychains[priority][entityframe5_prioritychaincounts[priority]++] = num;
+                       if (d->deltabits[num])
+                       {
+                               if (d->priorities[num] < (E5_PROTOCOL_PRIORITYLEVELS - 1))
+                                       d->priorities[num] = EntityState5_Priority(d, num);
+                               l = num;
+                               priority = d->priorities[num];
+                               if (entityframe5_prioritychaincounts[priority] < ENTITYFRAME5_MAXSTATES)
+                                       entityframe5_prioritychains[priority][entityframe5_prioritychaincounts[priority]++] = num;
+                       }
+                       else
+                               d->priorities[num] = 0;
                }
        }
 
@@ -2326,27 +2372,27 @@ void EntityFrame5_WriteFrame(sizebuf_t *msg, entityframe5_database_t *d, int num
        {
                for (i = 0;i < MAX_CL_STATS && msg->cursize + 6 + 11 <= msg->maxsize;i++)
                {
-                       if (d->statsdeltabits[i>>3] & (1<<(i&7)))
+                       if (host_client->statsdeltabits[i>>3] & (1<<(i&7)))
                        {
-                               d->statsdeltabits[i>>3] &= ~(1<<(i&7));
+                               host_client->statsdeltabits[i>>3] &= ~(1<<(i&7));
                                packetlog->statsdeltabits[i>>3] |= (1<<(i&7));
-                               if (d->stats[i] >= 0 && d->stats[i] < 256)
+                               if (host_client->stats[i] >= 0 && host_client->stats[i] < 256)
                                {
                                        MSG_WriteByte(msg, svc_updatestatubyte);
                                        MSG_WriteByte(msg, i);
-                                       MSG_WriteByte(msg, d->stats[i]);
+                                       MSG_WriteByte(msg, host_client->stats[i]);
                                }
                                else
                                {
                                        MSG_WriteByte(msg, svc_updatestat);
                                        MSG_WriteByte(msg, i);
-                                       MSG_WriteLong(msg, d->stats[i]);
+                                       MSG_WriteLong(msg, host_client->stats[i]);
                                }
                        }
                }
        }
        // write state updates
-       if (developer_networkentities.integer)
+       if (developer_networkentities.integer >= 10)
                Con_Printf("send: svc_entities %i\n", framenum);
        d->latestframenum = framenum;
        MSG_WriteByte(msg, svc_entities);
@@ -2383,43 +2429,43 @@ void EntityFrame5_WriteFrame(sizebuf_t *msg, entityframe5_database_t *d, int num
 }
 
 
-static int QW_TranslateEffects(int qweffects, int number)
+static void QW_TranslateEffects(entity_state_t *s, int qweffects)
 {
-       int effects = 0;
+       s->effects = 0;
+       s->internaleffects = 0;
        if (qweffects & QW_EF_BRIGHTFIELD)
-               effects |= EF_BRIGHTFIELD;
+               s->effects |= EF_BRIGHTFIELD;
        if (qweffects & QW_EF_MUZZLEFLASH)
-               effects |= EF_MUZZLEFLASH;
+               s->effects |= EF_MUZZLEFLASH;
        if (qweffects & QW_EF_FLAG1)
        {
                // mimic FTEQW's interpretation of EF_FLAG1 as EF_NODRAW on non-player entities
-               if (number > cl.maxclients)
-                       effects |= EF_NODRAW;
+               if (s->number > cl.maxclients)
+                       s->effects |= EF_NODRAW;
                else
-                       effects |= EF_FLAG1QW;
+                       s->internaleffects |= INTEF_FLAG1QW;
        }
        if (qweffects & QW_EF_FLAG2)
        {
                // mimic FTEQW's interpretation of EF_FLAG2 as EF_ADDITIVE on non-player entities
-               if (number > cl.maxclients)
-                       effects |= EF_ADDITIVE;
+               if (s->number > cl.maxclients)
+                       s->effects |= EF_ADDITIVE;
                else
-                       effects |= EF_FLAG2QW;
+                       s->internaleffects |= INTEF_FLAG2QW;
        }
        if (qweffects & QW_EF_RED)
        {
                if (qweffects & QW_EF_BLUE)
-                       effects |= EF_RED | EF_BLUE;
+                       s->effects |= EF_RED | EF_BLUE;
                else
-                       effects |= EF_RED;
+                       s->effects |= EF_RED;
        }
        else if (qweffects & QW_EF_BLUE)
-               effects |= EF_BLUE;
+               s->effects |= EF_BLUE;
        else if (qweffects & QW_EF_BRIGHTLIGHT)
-               effects |= EF_BRIGHTLIGHT;
+               s->effects |= EF_BRIGHTLIGHT;
        else if (qweffects & QW_EF_DIMLIGHT)
-               effects |= EF_DIMLIGHT;
-       return effects;
+               s->effects |= EF_DIMLIGHT;
 }
 
 void EntityStateQW_ReadPlayerUpdate(void)
@@ -2443,6 +2489,7 @@ void EntityStateQW_ReadPlayerUpdate(void)
        s = &ent->state_current;
        *s = defaultstate;
        s->active = true;
+       s->number = enumber;
        s->colormap = enumber;
        playerflags = MSG_ReadShort();
        MSG_ReadVector(s->origin, cls.protocol);
@@ -2495,7 +2542,7 @@ void EntityStateQW_ReadPlayerUpdate(void)
        if (playerflags & QW_PF_SKINNUM)
                s->skin = MSG_ReadByte();
        if (playerflags & QW_PF_EFFECTS)
-               s->effects = QW_TranslateEffects(MSG_ReadByte(), enumber);
+               QW_TranslateEffects(s, MSG_ReadByte());
        if (playerflags & QW_PF_WEAPONFRAME)
                weaponframe = MSG_ReadByte();
        else
@@ -2547,8 +2594,6 @@ void EntityStateQW_ReadPlayerUpdate(void)
        cl.entities_active[enumber] = s->active;
        // set the update time
        s->time = cl.mtime[0] - msec * 0.001; // qw has no clock
-       // 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)
                CL_MoveLerpEntityStates(&cl.entities[enumber]);
@@ -2574,7 +2619,7 @@ static void EntityStateQW_ReadEntityUpdate(entity_state_t *s, int bits)
        if (bits & QW_U_SKIN)
                s->skin = MSG_ReadByte();
        if (bits & QW_U_EFFECTS)
-               s->effects = QW_TranslateEffects(qweffects = MSG_ReadByte(), s->number);
+               QW_TranslateEffects(s, qweffects = MSG_ReadByte());
        if (bits & QW_U_ORIGIN1)
                s->origin[0] = MSG_ReadCoord13i();
        if (bits & QW_U_ANGLE1)