]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - protocol.c
analyzing the movement algorithm from warsow yielded that CPM_PM_Aircontrol is called...
[xonotic/darkplaces.git] / protocol.c
index d4931797b4aba6fedc29b87861bd0529af0e1972..748e23b341afce3775aa5456fb5dadfe85f9ca4f 100644 (file)
@@ -430,7 +430,7 @@ 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
-void 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 numstates, const entity_state_t *states, int framenum)
 {
        int num, number, end, sendflags;
        qboolean sectionstarted = false;
@@ -445,12 +445,12 @@ void EntityFrameCSQC_WriteFrame (sizebuf_t *msg, int maxsize, int numstates, con
 
        // if this server progs is not CSQC-aware, return early
        if(prog->fieldoffsets.SendEntity < 0 || prog->fieldoffsets.Version < 0)
-               return;
+               return false;
 
        // make sure there is enough room to store the svc_csqcentities byte,
        // the terminator (0x0000) and at least one entity update
        if (msg->cursize + 32 >= maxsize)
-               return;
+               return false;
 
        if (client->csqcnumedicts < prog->num_edicts)
                client->csqcnumedicts = prog->num_edicts;
@@ -597,6 +597,8 @@ void EntityFrameCSQC_WriteFrame (sizebuf_t *msg, int maxsize, int numstates, con
                // if no single ent got added, remove the frame from the DB again, to allow
                // for a larger history
                EntityFrameCSQC_DeallocFrame(client, framenum);
+       
+       return sectionstarted;
 }
 
 void Protocol_UpdateClientStats(const int *stats)
@@ -2009,6 +2011,7 @@ static int EntityState5_Priority(entityframe5_database_t *d, int stateindex)
 void EntityState5_WriteUpdate(int number, const entity_state_t *s, int changedbits, sizebuf_t *msg)
 {
        unsigned int bits = 0;
+       //dp_model_t *model;
        ENTITYSIZEPROFILING_START(msg, s->number);
 
        prvm_eval_t *val;
@@ -2021,7 +2024,8 @@ void EntityState5_WriteUpdate(int number, const entity_state_t *s, int changedbi
        else
        {
                bits = changedbits;
-               if ((bits & E5_ORIGIN) && ((s->flags & RENDER_EXTERIORMODEL) || 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))
+               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] == '*')
                        bits |= E5_ORIGIN32;
                        // possible values:
                        //   negative origin:
@@ -2495,7 +2499,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)
+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)
 {
        const entity_state_t *n;
        int i, num, l, framenum, packetlognumber, priority;
@@ -2600,10 +2604,7 @@ void EntityFrame5_WriteFrame(sizebuf_t *msg, int maxsize, entityframe5_database_
                }
        }
 
-       // add packetlog entry
-       packetlog = d->packetlog + packetlognumber;
-       packetlog->packetnumber = framenum;
-       packetlog->numstates = 0;
+       packetlog = NULL;
        // write stat updates
        if (sv.protocol != PROTOCOL_QUAKE && sv.protocol != PROTOCOL_QUAKEDP && sv.protocol != PROTOCOL_NEHAHRAMOVIE && sv.protocol != PROTOCOL_NEHAHRABJP && sv.protocol != PROTOCOL_NEHAHRABJP2 && sv.protocol != PROTOCOL_NEHAHRABJP3 && sv.protocol != PROTOCOL_DARKPLACES1 && sv.protocol != PROTOCOL_DARKPLACES2 && sv.protocol != PROTOCOL_DARKPLACES3 && sv.protocol != PROTOCOL_DARKPLACES4 && sv.protocol != PROTOCOL_DARKPLACES5)
        {
@@ -2612,22 +2613,44 @@ void EntityFrame5_WriteFrame(sizebuf_t *msg, int maxsize, entityframe5_database_
                        if (host_client->statsdeltabits[i>>3] & (1<<(i&7)))
                        {
                                host_client->statsdeltabits[i>>3] &= ~(1<<(i&7));
+                               // add packetlog entry now that we have something for it
+                               if (!packetlog)
+                               {
+                                       packetlog = d->packetlog + packetlognumber;
+                                       packetlog->packetnumber = framenum;
+                                       packetlog->numstates = 0;
+                               }
                                packetlog->statsdeltabits[i>>3] |= (1<<(i&7));
                                if (host_client->stats[i] >= 0 && host_client->stats[i] < 256)
                                {
                                        MSG_WriteByte(msg, svc_updatestatubyte);
                                        MSG_WriteByte(msg, i);
                                        MSG_WriteByte(msg, host_client->stats[i]);
+                                       l = 1;
                                }
                                else
                                {
                                        MSG_WriteByte(msg, svc_updatestat);
                                        MSG_WriteByte(msg, i);
                                        MSG_WriteLong(msg, host_client->stats[i]);
+                                       l = 1;
                                }
                        }
                }
        }
+
+       // only send empty svc_entities frame if needed
+       if(!l && !need_empty)
+               return;
+
+       // add packetlog entry now that we have something for it
+       if (!packetlog)
+       {
+               packetlog = d->packetlog + packetlognumber;
+               packetlog->packetnumber = framenum;
+               packetlog->numstates = 0;
+       }
+
        // write state updates
        if (developer_networkentities.integer >= 10)
                Con_Printf("send: svc_entities %i\n", framenum);