]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - protocol.c
added comments to cubemap loader, to explain its confusing logic
[xonotic/darkplaces.git] / protocol.c
index 86e760a51210bd82da3b4700127b7cfbfc20f9af..acb560bfc1167324ccce843d51a46dc069ac7ef0 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
                {
@@ -153,6 +163,12 @@ void EntityState_Write(entity_state_t *ent, sizebuf_t *msg, entity_state_t *delt
                                        MSG_WriteShort(msg, org[1]);
                                if (bits & E_ORIGIN3)
                                        MSG_WriteShort(msg, org[2]);
+                               if (bits & E_ANGLE1)
+                                       MSG_WriteAngle(msg, ent->angles[0]);
+                               if (bits & E_ANGLE2)
+                                       MSG_WriteAngle(msg, ent->angles[1]);
+                               if (bits & E_ANGLE3)
+                                       MSG_WriteAngle(msg, ent->angles[2]);
                        }
                        else
                        {
@@ -162,13 +178,13 @@ void EntityState_Write(entity_state_t *ent, sizebuf_t *msg, entity_state_t *delt
                                        MSG_WriteFloat(msg, org[1]);
                                if (bits & E_ORIGIN3)
                                        MSG_WriteFloat(msg, org[2]);
+                               if (bits & E_ANGLE1)
+                                       MSG_WritePreciseAngle(msg, ent->angles[0]);
+                               if (bits & E_ANGLE2)
+                                       MSG_WritePreciseAngle(msg, ent->angles[1]);
+                               if (bits & E_ANGLE3)
+                                       MSG_WritePreciseAngle(msg, ent->angles[2]);
                        }
-                       if (bits & E_ANGLE1)
-                               MSG_WriteAngle(msg, ent->angles[0]);
-                       if (bits & E_ANGLE2)
-                               MSG_WriteAngle(msg, ent->angles[1]);
-                       if (bits & E_ANGLE3)
-                               MSG_WriteAngle(msg, ent->angles[2]);
                        if (bits & E_MODEL1)
                                MSG_WriteByte(msg, ent->modelindex & 0xFF);
                        if (bits & E_MODEL2)
@@ -198,6 +214,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)
@@ -256,12 +283,24 @@ void EntityState_ReadUpdate(entity_state_t *e, int number)
                                e->origin[2] = MSG_ReadFloat();
                }
        }
-       if (bits & E_ANGLE1)
-               e->angles[0] = MSG_ReadAngle();
-       if (bits & E_ANGLE2)
-               e->angles[1] = MSG_ReadAngle();
-       if (bits & E_ANGLE3)
-               e->angles[2] = MSG_ReadAngle();
+       if (cl.protocol == PROTOCOL_DARKPLACES5 && !(e->flags & RENDER_LOWPRECISION))
+       {
+               if (bits & E_ANGLE1)
+                       e->angles[0] = MSG_ReadPreciseAngle();
+               if (bits & E_ANGLE2)
+                       e->angles[1] = MSG_ReadPreciseAngle();
+               if (bits & E_ANGLE3)
+                       e->angles[2] = MSG_ReadPreciseAngle();
+       }
+       else
+       {
+               if (bits & E_ANGLE1)
+                       e->angles[0] = MSG_ReadAngle();
+               if (bits & E_ANGLE2)
+                       e->angles[1] = MSG_ReadAngle();
+               if (bits & E_ANGLE3)
+                       e->angles[2] = MSG_ReadAngle();
+       }
        if (bits & E_MODEL1)
                e->modelindex = (e->modelindex & 0xFF00) | (unsigned int) MSG_ReadByte();
        if (bits & E_MODEL2)
@@ -294,6 +333,17 @@ 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 >= 2)
        {
@@ -328,13 +378,20 @@ 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);
-               Con_Printf("\n");
+               if (bits & E_LIGHTSTYLE)
+                       Con_Printf(" E_LIGHTSTYLE %i", e->lightstyle);
+               Con_Print("\n");
        }
 }
 
@@ -434,9 +491,9 @@ void EntityFrame_AddFrame(entity_database_t *d, entity_frame_t *f)
                if (e >= d->frames[n].framenum)
                {
                        if (e == f->framenum)
-                               Con_Printf("EntityFrame_AddFrame: tried to add out of sequence frame to database\n");
+                               Con_Print("EntityFrame_AddFrame: tried to add out of sequence frame to database\n");
                        else
-                               Con_Printf("EntityFrame_AddFrame: out of sequence frames in database\n");
+                               Con_Print("EntityFrame_AddFrame: out of sequence frames in database\n");
                        return;
                }
                e = d->frames[n].framenum;
@@ -665,6 +722,7 @@ void EntityFrame4_FreeDatabase(entity_database4_t *d)
 void EntityFrame4_ResetDatabase(entity_database4_t *d)
 {
        int i;
+       d->ackframenum = -1;
        d->referenceframenum = -1;
        for (i = 0;i < MAX_ENTITY_HISTORY;i++)
                d->commit[i].numentities = 0;
@@ -674,45 +732,60 @@ void EntityFrame4_ResetDatabase(entity_database4_t *d)
 
 int EntityFrame4_AckFrame(entity_database4_t *d, int framenum)
 {
-       int i, j, found = false;
+       int i, j, found;
        entity_database4_commit_t *commit;
-       if (d->referenceframenum == framenum)
-               return true;
        if (framenum == -1)
        {
-               EntityFrame4_ResetDatabase(d);
-               return true;
+               // reset reference, but leave commits alone
+               d->referenceframenum = -1;
+               for (i = 0;i < d->maxreferenceentities;i++)
+                       d->referenceentity[i] = defaultstate;
+               found = true;
        }
-       for (i = 0, commit = d->commit;i < MAX_ENTITY_HISTORY;i++, commit++)
+       else if (d->referenceframenum == framenum)
+               found = true;
+       else
        {
-               if (commit->numentities && commit->framenum <= framenum)
+               found = false;
+               for (i = 0, commit = d->commit;i < MAX_ENTITY_HISTORY;i++, commit++)
                {
-                       if (commit->framenum == framenum)
+                       if (commit->numentities && commit->framenum <= framenum)
                        {
-                               found = true;
-                               d->referenceframenum = framenum;
-                               if (developer_networkentities.integer >= 3)
+                               if (commit->framenum == framenum)
                                {
-                                       for (j = 0;j < commit->numentities;j++)
+                                       found = true;
+                                       d->referenceframenum = framenum;
+                                       if (developer_networkentities.integer >= 3)
                                        {
-                                               entity_state_t *s = EntityFrame4_GetReferenceEntity(d, commit->entity[j].number);
-                                               if (commit->entity[j].active != s->active)
+                                               for (j = 0;j < commit->numentities;j++)
                                                {
-                                                       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);
+                                                       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];
                                                }
-                                               *s = commit->entity[j];
                                        }
+                                       else
+                                               for (j = 0;j < commit->numentities;j++)
+                                                       *EntityFrame4_GetReferenceEntity(d, commit->entity[j].number) = commit->entity[j];
                                }
-                               else
-                                       for (j = 0;j < commit->numentities;j++)
-                                               *EntityFrame4_GetReferenceEntity(d, commit->entity[j].number) = commit->entity[j];
+                               commit->numentities = 0;
                        }
-                       commit->numentities = 0;
                }
        }
+       if (developer_networkentities.integer >= 1)
+       {
+               Con_Printf("ack ref:%i database updated to: ref:%i commits:", framenum, d->referenceframenum);
+               for (i = 0;i < MAX_ENTITY_HISTORY;i++)
+                       if (d->commit[i].numentities)
+                               Con_Printf(" %i", d->commit[i].framenum);
+               Con_Print("\n");
+       }
        return found;
 }
 
@@ -755,18 +828,16 @@ void EntityFrame4_CL_ReadFrame(entity_database4_t *d)
        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);
+               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++)
                        if (d->commit[i].numentities)
                                Con_Printf(" %i", d->commit[i].framenum);
-               Con_Printf("\n");
+               Con_Print("\n");
        }
        if (!EntityFrame4_AckFrame(d, referenceframenum))
        {
-               Con_Printf("EntityFrame4_CL_ReadFrame: reference frame invalid (VERY BAD ERROR), this update will be skipped\n");
+               Con_Print("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++)
@@ -859,6 +930,8 @@ void EntityFrame4_CL_ReadFrame(entity_database4_t *d)
                }
        }
        d->currentcommit = NULL;
+       if (skip)
+               EntityFrame4_ResetDatabase(d);
 }