]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - protocol.c
fixed black fullbrights on models in realtime mode
[xonotic/darkplaces.git] / protocol.c
index 1c95bdb1680b5ffa08da6c19d15abbe1f2464857..0ded4ed4e2c68f82a51bd9325b8f3b76c2ae7789 100644 (file)
@@ -17,6 +17,9 @@ entity_state_t defaultstate =
        0,//unsigned short exteriormodelforclient;
        0,//unsigned short nodrawtoclient;
        0,//unsigned short drawonlytoclient;
+       {0,0,0,0},//short light[4];
+       0,//qbyte lightstyle;
+       0,//qbyte lightpflags;
        0,//qbyte colormap;
        0,//qbyte skin;
        255,//qbyte alpha;
@@ -25,6 +28,7 @@ entity_state_t defaultstate =
        254,//qbyte glowcolor;
        0,//qbyte flags;
        0,//qbyte tagindex;
+       {0,0,0,0,0,0}//qbyte unused[6];
 };
 
 void ClearStateToDefault(entity_state_t *s)
@@ -120,6 +124,12 @@ void EntityState_Write(entity_state_t *ent, sizebuf_t *msg, entity_state_t *delt
                        bits |= E_FLAGS;
                if (ent->tagindex != delta->tagindex || ent->tagentity != delta->tagentity)
                        bits |= E_TAGATTACHMENT;
+               if (ent->light[0] != delta->light[0] || ent->light[1] != delta->light[1] || ent->light[2] != delta->light[2] || ent->light[3] != delta->light[3])
+                       bits |= E_LIGHT;
+               if (ent->lightstyle != delta->lightstyle)
+                       bits |= E_LIGHTSTYLE;
+               if (ent->lightpflags != delta->lightpflags)
+                       bits |= E_LIGHTPFLAGS;
 
                if (bits) // don't send anything if it hasn't changed
                {
@@ -198,6 +208,17 @@ void EntityState_Write(entity_state_t *ent, sizebuf_t *msg, entity_state_t *delt
                                MSG_WriteShort(msg, ent->tagentity);
                                MSG_WriteByte(msg, ent->tagindex);
                        }
+                       if (bits & E_LIGHT)
+                       {
+                               MSG_WriteShort(msg, ent->light[0]);
+                               MSG_WriteShort(msg, ent->light[1]);
+                               MSG_WriteShort(msg, ent->light[2]);
+                               MSG_WriteShort(msg, ent->light[3]);
+                       }
+                       if (bits & E_LIGHTSTYLE)
+                               MSG_WriteByte(msg, ent->lightstyle);
+                       if (bits & E_LIGHTPFLAGS)
+                               MSG_WriteByte(msg, ent->lightpflags);
                }
        }
        else if (delta->active)
@@ -294,8 +315,19 @@ void EntityState_ReadUpdate(entity_state_t *e, int number)
                e->tagentity = MSG_ReadShort();
                e->tagindex = MSG_ReadByte();
        }
+       if (bits & E_LIGHT)
+       {
+               e->light[0] = MSG_ReadShort();
+               e->light[1] = MSG_ReadShort();
+               e->light[2] = MSG_ReadShort();
+               e->light[3] = MSG_ReadShort();
+       }
+       if (bits & E_LIGHTSTYLE)
+               e->lightstyle = MSG_ReadByte();
+       if (bits & E_LIGHTPFLAGS)
+               e->lightpflags = MSG_ReadByte();
 
-       if (developer_networkentities.integer)
+       if (developer_networkentities.integer >= 2)
        {
                Con_Printf("ReadUpdate e%i", number);
 
@@ -328,12 +360,19 @@ void EntityState_ReadUpdate(entity_state_t *e, int number)
                        Con_Printf(" E_SKIN %i", e->skin);
 
                if (bits & E_GLOWSIZE)
-                       Con_Printf(" E_GLOWSIZE %i", e->glowsize * 8);
+                       Con_Printf(" E_GLOWSIZE %i", e->glowsize * 4);
                if (bits & E_GLOWCOLOR)
                        Con_Printf(" E_GLOWCOLOR %i", e->glowcolor);
+               
+               if (bits & E_LIGHT)
+                       Con_Printf(" E_LIGHT %i:%i:%i:%i", e->light[0], e->light[1], e->light[2], e->light[3]);
+               if (bits & E_LIGHTPFLAGS)                       
+                       Con_Printf(" E_LIGHTPFLAGS %i", e->lightpflags);
 
                if (bits & E_TAGATTACHMENT)
                        Con_Printf(" E_TAGATTACHMENT e%i:%i", e->tagentity, e->tagindex);
+               if (bits & E_LIGHTSTYLE)
+                       Con_Printf(" E_LIGHTSTYLE %i", e->lightstyle);
                Con_Printf("\n");
        }
 }
@@ -601,24 +640,6 @@ int EntityFrame_MostRecentlyRecievedFrameNum(entity_database_t *d)
 
 
 
-int EntityFrame4_SV_ChooseCommitToReplace(entity_database4_t *d)
-{
-       int i, best, bestframenum;
-       best = 0;
-       bestframenum = d->commit[0].framenum;
-       for (i = 0;i < MAX_ENTITY_HISTORY;i++)
-       {
-               if (!d->commit[i].numentities)
-                       return i;
-               if (bestframenum > d->commit[i].framenum)
-               {
-                       bestframenum = d->commit[i].framenum;
-                       best = i;
-               }
-       }
-       return best;
-}
-
 entity_state_t *EntityFrame4_GetReferenceEntity(entity_database4_t *d, int number)
 {
        if (d->maxreferenceentities <= number)
@@ -690,60 +711,48 @@ void EntityFrame4_ResetDatabase(entity_database4_t *d)
                d->referenceentity[i] = defaultstate;
 }
 
-void EntityFrame4_AckFrame(entity_database4_t *d, int framenum)
+int EntityFrame4_AckFrame(entity_database4_t *d, int framenum)
 {
-       int i, j;
+       int i, j, found = false;
        entity_database4_commit_t *commit;
-       // check if the peer is requesting no delta compression
+       if (d->referenceframenum == framenum)
+               return true;
        if (framenum == -1)
        {
                EntityFrame4_ResetDatabase(d);
-               return;
+               return true;
        }
-       // return early if this is already the reference frame
-       if (d->referenceframenum == framenum)
-               return;
-       // find the frame in the database
        for (i = 0, commit = d->commit;i < MAX_ENTITY_HISTORY;i++, commit++)
-               if (commit->numentities && commit->framenum == framenum)
-                       break;
-       // check if the frame was found
-       if (i == MAX_ENTITY_HISTORY)
        {
-               Con_Printf("EntityFrame4_AckFrame: frame %i not found in database, expect glitches!  (VERY BAD ERROR)\n", framenum);
-               d->ackframenum = -1;
-               EntityFrame4_ResetDatabase(d);
-               return;
-       }
-       // apply commit to database
-       d->referenceframenum = framenum;
-       for (j = 0;j < commit->numentities;j++)
-       {
-               //*EntityFrame4_GetReferenceEntity(d, commit->entity[j].number) = commit->entity[j];
-               entity_state_t *s = EntityFrame4_GetReferenceEntity(d, commit->entity[j].number);
-               if (developer_networkentities.integer && commit->entity[j].active != s->active)
+               if (commit->numentities && commit->framenum <= framenum)
                {
-                       if (commit->entity[j].active)
-                               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);
+                       if (commit->framenum == framenum)
+                       {
+                               found = true;
+                               d->referenceframenum = framenum;
+                               if (developer_networkentities.integer >= 3)
+                               {
+                                       for (j = 0;j < commit->numentities;j++)
+                                       {
+                                               entity_state_t *s = EntityFrame4_GetReferenceEntity(d, commit->entity[j].number);
+                                               if (commit->entity[j].active != s->active)
+                                               {
+                                                       if (commit->entity[j].active)
+                                                               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);
+                                               }
+                                               *s = commit->entity[j];
+                                       }
+                               }
+                               else
+                                       for (j = 0;j < commit->numentities;j++)
+                                               *EntityFrame4_GetReferenceEntity(d, commit->entity[j].number) = commit->entity[j];
+                       }
+                       commit->numentities = 0;
                }
-               *s = commit->entity[j];
        }
-       // purge the now-obsolete updates
-       for (i = 0;i < MAX_ENTITY_HISTORY;i++)
-               if (d->commit[i].framenum <= framenum)
-                       d->commit[i].numentities = 0;
-}
-
-void EntityFrame4_SV_WriteFrame_Begin(entity_database4_t *d, sizebuf_t *msg, int framenum)
-{
-       d->currentcommit = d->commit + EntityFrame4_SV_ChooseCommitToReplace(d);
-       d->currentcommit->numentities = 0;
-       d->currentcommit->framenum = framenum;
-       MSG_WriteByte(msg, svc_entities);
-       MSG_WriteLong(msg, d->referenceframenum);
-       MSG_WriteLong(msg, d->currentcommit->framenum);
+       return found;
 }
 
 int EntityFrame4_SV_WriteFrame_Entity(entity_database4_t *d, sizebuf_t *msg, int maxbytes, entity_state_t *s)
@@ -773,14 +782,6 @@ int EntityFrame4_SV_WriteFrame_Entity(entity_database4_t *d, sizebuf_t *msg, int
        return true;
 }
 
-void EntityFrame4_SV_WriteFrame_End(entity_database4_t *d, sizebuf_t *msg)
-{
-       // remove world message (invalid, and thus a good terminator)
-       MSG_WriteShort(msg, 0x8000);
-       // just to be sure
-       d->currentcommit = NULL;
-}
-
 extern void CL_MoveLerpEntityStates(entity_t *ent);
 void EntityFrame4_CL_ReadFrame(entity_database4_t *d)
 {
@@ -791,22 +792,32 @@ void EntityFrame4_CL_ReadFrame(entity_database4_t *d)
        framenum = MSG_ReadLong();
        // read the start number
        enumber = MSG_ReadShort();
+       if (developer_networkentities.integer >= 1)
+       {
+               Con_Printf("recv svc_entities ref:%i num:%i (database: ref:%i commits:", referenceframenum, framenum, d->referenceframenum);
+               for (i = 0;i < MAX_ENTITY_HISTORY;i++)
+                       if (d->commit[i].numentities)
+                               Con_Printf(" %i", d->commit[i].framenum);
+               Con_Printf("\n");
+       }
+       if (!EntityFrame4_AckFrame(d, referenceframenum))
+       {
+               Con_Printf("EntityFrame4_CL_ReadFrame: reference frame invalid (VERY BAD ERROR), this update will be skipped\n");
+               skip = true;
+               d->ackframenum = -1;
+               EntityFrame4_ResetDatabase(d);
+       }
+       d->currentcommit = NULL;
        for (i = 0;i < MAX_ENTITY_HISTORY;i++)
-               if (!d->commit[i].numentities)
-                       break;
-       if (i < MAX_ENTITY_HISTORY)
        {
-               d->currentcommit = d->commit + i;
-               d->currentcommit->framenum = d->ackframenum = framenum;
-               d->currentcommit->numentities = 0;
-               EntityFrame4_AckFrame(d, referenceframenum);
-               if (d->ackframenum == -1)
+               if (!d->commit[i].numentities)
                {
-                       Con_Printf("EntityFrame4_CL_ReadFrame: reference frame invalid, this update will be skipped\n");
-                       skip = true;
+                       d->currentcommit = d->commit + i;
+                       d->currentcommit->framenum = d->ackframenum = framenum;
+                       d->currentcommit->numentities = 0;
                }
        }
-       else
+       if (d->currentcommit == NULL)
        {
                Con_Printf("EntityFrame4_CL_ReadFrame: error while decoding frame %i: database full, reading but not storing this update\n", framenum);
                skip = true;
@@ -851,20 +862,20 @@ void EntityFrame4_CL_ReadFrame(entity_database4_t *d)
                                if (n & 0x8000)
                                {
                                        // simply removed
-                                       if (developer_networkentities.integer)
+                                       if (developer_networkentities.integer >= 2)
                                                Con_Printf("entity %i: remove\n", enumber);
                                        cl_entities[enumber].state_current = defaultstate;
                                }
                                else
                                {
                                        // read the changes
-                                       if (developer_networkentities.integer)
+                                       if (developer_networkentities.integer >= 2)
                                                Con_Printf("entity %i: update\n", enumber);
                                        EntityState_ReadUpdate(&cl_entities[enumber].state_current, enumber);
                                }
                        }
-                       //else if (developer_networkentities.integer)
-                       //      Con_Printf("entity %i: copy\n", enumber);
+                       else if (developer_networkentities.integer >= 4)
+                               Con_Printf("entity %i: copy\n", enumber);
                        // fix the number (it gets wiped occasionally by copying from defaultstate)
                        cl_entities[enumber].state_current.number = enumber;
                        // check if we need to update the lerp stuff
@@ -877,7 +888,7 @@ void EntityFrame4_CL_ReadFrame(entity_database4_t *d)
                        if (d->currentcommit)
                                EntityFrame4_AddCommitEntity(d, &cl_entities[enumber].state_current);
                        // print extra messages if desired
-                       if (developer_networkentities.integer && cl_entities[enumber].state_current.active != cl_entities[enumber].state_previous.active)
+                       if (developer_networkentities.integer >= 2 && cl_entities[enumber].state_current.active != cl_entities[enumber].state_previous.active)
                        {
                                if (cl_entities[enumber].state_current.active)
                                        Con_Printf("entity #%i has become active\n", enumber);