Eliminate MAX_VISEDICTS. Unlimited visible entities.

The renderer can now render as many entities as can be crammed into the
currently visible set of nodes.
This commit is contained in:
Bill Currie 2010-12-03 14:54:39 +09:00
parent abe0c50a2a
commit a6941e27ef
9 changed files with 58 additions and 61 deletions

View file

@ -74,6 +74,8 @@ extern lightstyle_t r_lightstyle[MAX_LIGHTSTYLES];
typedef struct entity_s { typedef struct entity_s {
struct entity_s *next;
vec3_t origin; vec3_t origin;
vec3_t old_origin; vec3_t old_origin;
vec3_t angles; vec3_t angles;
@ -199,7 +201,7 @@ void R_LoadSkys (const char *);
void R_ClearEfrags (void); void R_ClearEfrags (void);
void R_ClearEnts (void); void R_ClearEnts (void);
struct entity_s **R_NewEntity (void); void R_EnqueueEntity (struct entity_s *ent);
dlight_t *R_AllocDlight (int key); dlight_t *R_AllocDlight (int key);
void R_DecayLights (double frametime); void R_DecayLights (double frametime);

View file

@ -306,8 +306,7 @@ extern int r_clipflags;
extern int r_dlightframecount; extern int r_dlightframecount;
extern qboolean r_fov_greater_than_90; extern qboolean r_fov_greater_than_90;
extern int r_numvisedicts; extern struct entity_s *r_ent_queue;
extern struct entity_s *r_visedicts[];
struct dlight_s; struct dlight_s;
void R_StoreEfrags (const efrag_t *ppefrag); void R_StoreEfrags (const efrag_t *ppefrag);

View file

@ -533,6 +533,7 @@ gl_overbright_f (cvar_t *var)
int num, i, j; int num, i, j;
model_t *m; model_t *m;
msurface_t *fa; msurface_t *fa;
entity_t *ent;
if (!var) if (!var)
return; return;
@ -578,8 +579,8 @@ gl_overbright_f (cvar_t *var)
if (!R_BuildLightMap) if (!R_BuildLightMap)
return; return;
for (i = 0; i < r_numvisedicts; i++) { for (ent = r_ent_queue; ent; ent = ent->next) {
m = r_visedicts[i]->model; m = ent->model;
if (m->type != mod_brush) if (m->type != mod_brush)
continue; continue;

View file

@ -219,16 +219,16 @@ R_RotateForEntity (entity_t *e)
static void static void
R_DrawEntitiesOnList (void) R_DrawEntitiesOnList (void)
{ {
int i; entity_t *ent;
if (!r_drawentities->int_val) if (!r_drawentities->int_val)
return; return;
// LordHavoc: split into 3 loops to simplify state changes // LordHavoc: split into 3 loops to simplify state changes
for (i = 0; i < r_numvisedicts; i++) { for (ent = r_ent_queue; ent; ent = ent->next) {
if (r_visedicts[i]->model->type != mod_brush) if (ent->model->type != mod_brush)
continue; continue;
currententity = r_visedicts[i]; currententity = ent;
R_DrawBrushModel (currententity); R_DrawBrushModel (currententity);
} }
@ -253,10 +253,10 @@ R_DrawEntitiesOnList (void)
qfglEnable (GL_NORMALIZE); qfglEnable (GL_NORMALIZE);
} }
for (i = 0; i < r_numvisedicts; i++) { for (ent = r_ent_queue; ent; ent = ent->next) {
if (r_visedicts[i]->model->type != mod_alias) if (ent->model->type != mod_alias)
continue; continue;
currententity = r_visedicts[i]; currententity = ent;
R_DrawAliasModel (currententity); R_DrawAliasModel (currententity);
} }
@ -289,10 +289,10 @@ R_DrawEntitiesOnList (void)
qfglEnable (GL_ALPHA_TEST); qfglEnable (GL_ALPHA_TEST);
if (gl_va_capable) if (gl_va_capable)
qfglInterleavedArrays (GL_T2F_C4UB_V3F, 0, spriteVertexArray); qfglInterleavedArrays (GL_T2F_C4UB_V3F, 0, spriteVertexArray);
for (i = 0; i < r_numvisedicts; i++) { for (ent = r_ent_queue; ent; ent = ent->next) {
if (r_visedicts[i]->model->type != mod_sprite) if (ent->model->type != mod_sprite)
continue; continue;
currententity = r_visedicts[i]; currententity = ent;
R_DrawSpriteModel (currententity); R_DrawSpriteModel (currententity);
} }
@ -540,7 +540,6 @@ static void
R_Mirror (void) R_Mirror (void)
{ {
float d; float d;
entity_t **ent;
msurface_t *s; msurface_t *s;
// if (!mirror) // FIXME: Broken // if (!mirror) // FIXME: Broken
@ -560,9 +559,7 @@ R_Mirror (void)
r_refdef.viewangles[1] = atan2 (vpn[1], vpn[0]) / M_PI * 180; r_refdef.viewangles[1] = atan2 (vpn[1], vpn[0]) / M_PI * 180;
r_refdef.viewangles[2] = -r_refdef.viewangles[2]; r_refdef.viewangles[2] = -r_refdef.viewangles[2];
ent = R_NewEntity(); R_EnqueueEntity (r_player_entity);
if (ent)
*ent = r_player_entity;
gldepthmin = 0.5; gldepthmin = 0.5;
gldepthmax = 1; gldepthmax = 1;

View file

@ -232,11 +232,7 @@ R_StoreEfrags (const efrag_t *pefrag)
pent = pefrag->entity; pent = pefrag->entity;
if (pent->visframe != r_framecount) { if (pent->visframe != r_framecount) {
entity_t **ent = R_NewEntity (); R_EnqueueEntity (pent);
if (!ent)
return;
*ent = pent;
// mark that we've recorded this entity for this frame // mark that we've recorded this entity for this frame
pent->visframe = r_framecount; pent->visframe = r_framecount;
} }

View file

@ -49,22 +49,20 @@ static __attribute__ ((used)) const char rcsid[] =
#include "r_dynamic.h" #include "r_dynamic.h"
#define MAX_VISEDICTS 256 entity_t *r_ent_queue;
int r_numvisedicts; static entity_t **vis_tail = &r_ent_queue;
entity_t *r_visedicts[MAX_VISEDICTS];
void void
R_ClearEnts (void) R_ClearEnts (void)
{ {
r_numvisedicts = 0; r_ent_queue = 0;
vis_tail = &r_ent_queue;
} }
entity_t ** void
R_NewEntity (void) R_EnqueueEntity (entity_t *ent)
{ {
ent->next = 0;
if (r_numvisedicts == MAX_VISEDICTS) *vis_tail = ent;
return NULL; vis_tail = &ent->next;
return &r_visedicts[r_numvisedicts++];
} }

View file

@ -409,9 +409,10 @@ R_MarkLeaves (void)
static void static void
R_DrawEntitiesOnList (void) R_DrawEntitiesOnList (void)
{ {
int i, j; int j;
unsigned int lnum; unsigned int lnum;
alight_t lighting; alight_t lighting;
entity_t *ent;
// FIXME: remove and do real lighting // FIXME: remove and do real lighting
float lightvec[3] = { -1, 0, 0 }; float lightvec[3] = { -1, 0, 0 };
@ -422,8 +423,8 @@ R_DrawEntitiesOnList (void)
if (!r_drawentities->int_val) if (!r_drawentities->int_val)
return; return;
for (i = 0; i < r_numvisedicts; i++) { for (ent = r_ent_queue; ent; ent = ent->next) {
currententity = r_visedicts[i]; currententity = ent;
switch (currententity->model->type) { switch (currententity->model->type) {
case mod_sprite: case mod_sprite:
@ -595,11 +596,12 @@ R_BmodelCheckBBox (model_t *clmodel, float *minmaxs)
static void static void
R_DrawBEntitiesOnList (void) R_DrawBEntitiesOnList (void)
{ {
int i, j, clipflags; int j, clipflags;
unsigned int k; unsigned int k;
vec3_t oldorigin; vec3_t oldorigin;
model_t *clmodel; model_t *clmodel;
float minmaxs[6]; float minmaxs[6];
entity_t *ent;
if (!r_drawentities->int_val) if (!r_drawentities->int_val)
return; return;
@ -607,8 +609,8 @@ R_DrawBEntitiesOnList (void)
VectorCopy (modelorg, oldorigin); VectorCopy (modelorg, oldorigin);
insubmodel = true; insubmodel = true;
for (i = 0; i < r_numvisedicts; i++) { for (ent = r_ent_queue; ent; ent = ent->next) {
currententity = r_visedicts[i]; currententity = ent;
switch (currententity->model->type) { switch (currententity->model->type) {
case mod_brush: case mod_brush:

View file

@ -429,9 +429,10 @@ R_MarkLeaves (void)
static void static void
R_DrawEntitiesOnList (void) R_DrawEntitiesOnList (void)
{ {
int i, j; int j;
unsigned int lnum; unsigned int lnum;
alight_t lighting; alight_t lighting;
entity_t *ent;
// FIXME: remove and do real lighting // FIXME: remove and do real lighting
float lightvec[3] = { -1, 0, 0 }; float lightvec[3] = { -1, 0, 0 };
@ -442,8 +443,8 @@ R_DrawEntitiesOnList (void)
if (!r_drawentities->int_val) if (!r_drawentities->int_val)
return; return;
for (i = 0; i < r_numvisedicts; i++) { for (ent = r_ent_queue; ent; ent = ent->next) {
currententity = r_visedicts[i]; currententity = ent;
switch (currententity->model->type) { switch (currententity->model->type) {
case mod_sprite: case mod_sprite:
@ -614,11 +615,12 @@ R_BmodelCheckBBox (model_t *clmodel, float *minmaxs)
static void static void
R_DrawBEntitiesOnList (void) R_DrawBEntitiesOnList (void)
{ {
int i, j, clipflags; int j, clipflags;
unsigned int k; unsigned int k;
vec3_t oldorigin; vec3_t oldorigin;
model_t *clmodel; model_t *clmodel;
float minmaxs[6]; float minmaxs[6];
entity_t *ent;
if (!r_drawentities->int_val) if (!r_drawentities->int_val)
return; return;
@ -626,8 +628,8 @@ R_DrawBEntitiesOnList (void)
VectorCopy (modelorg, oldorigin); VectorCopy (modelorg, oldorigin);
insubmodel = true; insubmodel = true;
for (i = 0; i < r_numvisedicts; i++) { for (ent = r_ent_queue; ent; ent = ent->next) {
currententity = r_visedicts[i]; currententity = ent;
switch (currententity->model->type) { switch (currententity->model->type) {
case mod_brush: case mod_brush:

View file

@ -769,8 +769,7 @@ CL_AddFlagModels (entity_t *ent, int team, int key)
16.0, 24.0, 24.0, 22.0, 18.0, 16.0, // 35-40 pain 16.0, 24.0, 24.0, 22.0, 18.0, 16.0, // 35-40 pain
}; };
float f; float f;
int i; entity_t *fent;
entity_t **newent;
vec3_t v_forward, v_right, v_up; vec3_t v_forward, v_right, v_up;
if (cl_flagindex == -1) if (cl_flagindex == -1)
@ -786,21 +785,22 @@ CL_AddFlagModels (entity_t *ent, int team, int key)
f = 21.0; // 112-118 shotattack f = 21.0; // 112-118 shotattack
} }
newent = R_NewEntity (); fent = &cl_flag_ents[key];
if (!newent) fent->model = cl.model_precache[cl_flagindex];
return; fent->skinnum = team;
*newent = &cl_flag_ents[key];
(*newent)->model = cl.model_precache[cl_flagindex];
(*newent)->skinnum = team;
AngleVectors (ent->angles, v_forward, v_right, v_up); AngleVectors (ent->angles, v_forward, v_right, v_up);
v_forward[2] = -v_forward[2]; // reverse z component v_forward[2] = -v_forward[2]; // reverse z component
for (i = 0; i < 3; i++)
(*newent)->origin[i] = ent->origin[i] - f * v_forward[i] + VectorMultAdd (ent->origin, -f, v_forward, fent->origin);
22.0 * v_right[i]; VectorMultAdd (fent->origin, 22, v_right, fent->origin);
(*newent)->origin[2] -= 16.0; fent->origin[2] -= 16.0;
VectorCopy (ent->angles, (*newent)->angles);
(*newent)->angles[2] -= 45.0; VectorCopy (ent->angles, fent->angles);
fent->angles[2] -= 45.0;
R_EnqueueEntity (fent); //FIXME should use efrag (needs smarter handling
//in the player code)
} }
/* /*