From 9d9c9ef007e072479ed519c6fdc3cacf91afd41a Mon Sep 17 00:00:00 2001 From: havoc Date: Fri, 9 Feb 2007 21:17:37 +0000 Subject: [PATCH] changed entity priority code again, it should have less 'starvation' issues now (high priority entities causing others to be missed) git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@6815 d7cf8633-e32d-0410-b094-e92efae38249 --- protocol.c | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/protocol.c b/protocol.c index 92f5d637..561ca0e1 100644 --- a/protocol.c +++ b/protocol.c @@ -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)) -- 2.39.2