]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
fix a clientside bug with CL_ValidateState altering entity states and
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 9 Aug 2007 05:16:37 +0000 (05:16 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 9 Aug 2007 05:16:37 +0000 (05:16 +0000)
causing them to remain altered in the future on delta updates in DP5/6/7
protocols (for example if skin or frame was set to a value that is not
valid on the current model, and then the model changes without the skin
or frame changing, it would be stuck on skin 0 or frame 0 until they
change to something else)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7508 d7cf8633-e32d-0410-b094-e92efae38249

cl_main.c
cl_parse.c

index b75d97a217130366fdb8e4a28307d6da6f195bd8..e1172e52c169ad07141b39a4776b3eae11397f3e 100644 (file)
--- a/cl_main.c
+++ b/cl_main.c
@@ -834,7 +834,7 @@ void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolat
 {
        const matrix4x4_t *matrix;
        matrix4x4_t blendmatrix, tempmatrix, matrix2;
-       int j, k, l;
+       int j, k, l, frame;
        float origin[3], angles[3], delta[3], lerp, d;
        entity_t *t;
        model_t *model;
@@ -867,7 +867,7 @@ void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolat
                e->render.colormap_shirtcolor[1] = cbcolor[1] * (1.0f / 255.0f);
                e->render.colormap_shirtcolor[2] = cbcolor[2] * (1.0f / 255.0f);
        }
-       else if (e->state_current.colormap && cl.scores != NULL)
+       else if (e->state_current.colormap && cl.scores != NULL && e->state_current.colormap <= cl.maxclients)
        {
                int cb;
                unsigned char *cbcolor;
@@ -977,10 +977,17 @@ void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolat
        }
 
        // model setup and some modelflags
-       if(e->state_current.modelindex < MAX_MODELS)
+       frame = e->state_current.frame;
+       if (e->state_current.modelindex < MAX_MODELS)
                e->render.model = cl.model_precache[e->state_current.modelindex];
+       else
+               e->render.model = NULL;
        if (e->render.model)
        {
+               if (e->render.skinnum >= e->render.model->numskins)
+                       e->render.skinnum = 0;
+               if (frame >= e->render.model->numframes)
+                       frame = 0;
                // models can set flags such as EF_ROCKET
                // this 0xFF800000 mask is EF_NOMODELFLAGS plus all the higher EF_ flags such as EF_ROCKET
                if (!(e->render.effects & 0xFF800000))
@@ -1003,7 +1010,7 @@ void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolat
        }
 
        // animation lerp
-       if (e->render.frame2 == e->state_current.frame)
+       if (e->render.frame2 == frame)
        {
                // update frame lerp fraction
                e->render.framelerp = 1;
@@ -1021,7 +1028,7 @@ void CL_UpdateNetworkEntity(entity_t *e, int recursionlimit, qboolean interpolat
                // begin a new frame lerp
                e->render.frame1 = e->render.frame2;
                e->render.frame1time = e->render.frame2time;
-               e->render.frame2 = e->state_current.frame;
+               e->render.frame2 = frame;
                e->render.frame2time = cl.time;
                e->render.framelerp = 0;
        }
index bf145348484de7e1b5d3845875709bc3d6094778..dc4e748dc92b566fb571b0705fc687a3324401a7 100644 (file)
@@ -1635,30 +1635,25 @@ void CL_ValidateState(entity_state_t *s)
        if (s->modelindex >= MAX_MODELS)
                Host_Error("CL_ValidateState: modelindex (%i) >= MAX_MODELS (%i)\n", s->modelindex, MAX_MODELS);
 
+       // these warnings are only warnings, no corrections are made to the state
+       // because states are often copied for decoding, which otherwise would
+       // propogate some of the corrections accidentally
+       // (this used to happen, sometimes affecting skin and frame)
+
        // colormap is client index + 1
        if ((!s->flags & RENDER_COLORMAPPED) && s->colormap > cl.maxclients)
-       {
                Con_DPrintf("CL_ValidateState: colormap (%i) > cl.maxclients (%i)\n", s->colormap, cl.maxclients);
-               s->colormap = 0;
-       }
 
        model = cl.model_precache[s->modelindex];
        if (model && model->type && s->frame >= model->numframes)
-       {
                Con_DPrintf("CL_ValidateState: no such frame %i in \"%s\" (which has %i frames)\n", s->frame, model->name, model->numframes);
-               s->frame = 0;
-       }
        if (model && model->type && s->skin > 0 && s->skin >= model->numskins && !(s->lightpflags & PFLAGS_FULLDYNAMIC))
-       {
                Con_DPrintf("CL_ValidateState: no such skin %i in \"%s\" (which has %i skins)\n", s->skin, model->name, model->numskins);
-               s->skin = 0;
-       }
 }
 
 void CL_MoveLerpEntityStates(entity_t *ent)
 {
        float odelta[3], adelta[3];
-       CL_ValidateState(&ent->state_current);
        VectorSubtract(ent->state_current.origin, ent->persistent.neworigin, odelta);
        VectorSubtract(ent->state_current.angles, ent->persistent.newangles, adelta);
        if (!ent->state_previous.active || ent->state_previous.modelindex != ent->state_current.modelindex)