]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
changed entity priority code again, it should have less 'starvation' issues now ...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 9 Feb 2007 21:17:37 +0000 (21:17 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 9 Feb 2007 21:17:37 +0000 (21:17 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6815 d7cf8633-e32d-0410-b094-e92efae38249

protocol.c

index 92f5d637a0252227e00eab94aeec4d4c5453a6d3..561ca0e1bec5b7b11e81659e3a77cae0d622f6c7 100644 (file)
@@ -1645,44 +1645,44 @@ void EntityFrame5_ExpandEdicts(entityframe5_database_t *d, int newmax)
 
 int EntityState5_Priority(entityframe5_database_t *d, int stateindex)
 {
-       int lowprecision, limit, priority;
+       int limit, priority;
        double distance;
        int changedbits;
-       entity_state_t *view, *s;
-       changedbits = d->deltabits[stateindex];
+       entity_state_t *s;
+       // if it is the player, update urgently
+       if (stateindex == d->viewentnum)
+               return E5_PROTOCOL_PRIORITYLEVELS - 1;
        priority = d->priorities[stateindex];
        // remove dead entities very quickly because they are just 2 bytes
        if (!d->states[stateindex].active)
-               return E5_PROTOCOL_PRIORITYLEVELS - 1;
-       // check whole attachment chain to judge relevance to player
-       view = d->states + d->viewentnum;
-       lowprecision = false;
+               return bound(1, priority + 1, E5_PROTOCOL_PRIORITYLEVELS - 1);
+       changedbits = d->deltabits[stateindex];
+       // find the root entity this one is attached to, and judge relevance by it
        for (limit = 0;limit < 256;limit++)
        {
-               if (d->maxedicts < stateindex)
-                       EntityFrame5_ExpandEdicts(d, (stateindex+256)&~255);
                s = d->states + stateindex;
-               // if it is the player, update urgently
-               if (s == view)
-                       return E5_PROTOCOL_PRIORITYLEVELS - 1;
-               // if it is one of the player's viewmodels, update urgently
                if (s->flags & RENDER_VIEWMODEL)
-                       return E5_PROTOCOL_PRIORITYLEVELS - 1;
-               if (s->flags & RENDER_LOWPRECISION)
-                       lowprecision = true;
-               if (!s->tagentity)
+                       stateindex = d->viewentnum;
+               else if (s->tagentity)
+                       stateindex = s->tagentity;
+               else
                        break;
-               stateindex = s->tagentity;
+               if (d->maxedicts < stateindex)
+                       EntityFrame5_ExpandEdicts(d, (stateindex+256)&~255);
        }
        if (limit >= 256)
                Con_DPrintf("Protocol: Runaway loop recursing tagentity links on entity %i\n", stateindex);
        // now that we have the parent entity we can make some decisions based on
        // distance and other factors
        // TODO: add velocity check for things moving toward you (+1 priority)
-       distance = VectorDistance(view->origin, s->origin);
+       distance = VectorDistance(d->states[d->viewentnum].origin, s->origin);
        // if it is not far from the player, update more often
-       if (distance < 1024.0f && !lowprecision)
+       if (distance < 256.0f)
+               priority++;
+       // if it is not very far from the player, update more often
+       if (distance < 1024.0f)
                priority++;
+       // certain changes are more noticable than others
        if (changedbits & E5_FULLUPDATE)
                priority++;
        if (changedbits & (E5_ATTACHMENT | E5_MODEL | E5_FLAGS | E5_COLORMAP))