From: black Date: Sat, 5 Jan 2008 03:18:52 +0000 (+0000) Subject: This is also worth merging back into DP's trunk at once: X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=56ec5fd4cef83b79ed57c2cf50c25f601139853e;p=xonotic%2Fdarkplaces.git This is also worth merging back into DP's trunk at once: Cleaned up temp entity use to only provide render entities (the entity was never ever used). This fixes the last big hack in the menu rendering. Although some function need to be renamed to R_ instead of CL_ (and also moved around then..) git-svn-id: svn://svn.icculus.org/twilight/branches/dp-mqc-render/darkplaces@7911 d7cf8633-e32d-0410-b094-e92efae38249 --- diff --git a/cl_main.c b/cl_main.c index 02f0bd0e..8126e1e3 100644 --- a/cl_main.c +++ b/cl_main.c @@ -124,13 +124,11 @@ void CL_ClearState(void) cl.num_entities = 0; cl.num_static_entities = 0; - cl.num_temp_entities = 0; cl.num_brushmodel_entities = 0; // tweak these if the game runs out cl.max_entities = 256; cl.max_static_entities = 256; - cl.max_temp_entities = 512; cl.max_effects = 256; cl.max_beams = 256; cl.max_dlights = MAX_DLIGHTS; @@ -156,7 +154,6 @@ void CL_ClearState(void) cl.entities = (entity_t *)Mem_Alloc(cls.levelmempool, cl.max_entities * sizeof(entity_t)); cl.entities_active = (unsigned char *)Mem_Alloc(cls.levelmempool, cl.max_brushmodel_entities * sizeof(unsigned char)); cl.static_entities = (entity_t *)Mem_Alloc(cls.levelmempool, cl.max_static_entities * sizeof(entity_t)); - cl.temp_entities = (entity_t *)Mem_Alloc(cls.levelmempool, cl.max_temp_entities * sizeof(entity_t)); cl.effects = (cl_effect_t *)Mem_Alloc(cls.levelmempool, cl.max_effects * sizeof(cl_effect_t)); cl.beams = (beam_t *)Mem_Alloc(cls.levelmempool, cl.max_beams * sizeof(beam_t)); cl.dlights = (dlight_t *)Mem_Alloc(cls.levelmempool, cl.max_dlights * sizeof(dlight_t)); @@ -604,24 +601,24 @@ static float CL_LerpPoint(void) void CL_ClearTempEntities (void) { - cl.num_temp_entities = 0; + r_refdef.numtempentities = 0; } -entity_t *CL_NewTempEntity(void) +entity_render_t *CL_NewTempEntity(void) { - entity_t *ent; + entity_render_t *render; if (r_refdef.numentities >= r_refdef.maxentities) return NULL; - if (cl.num_temp_entities >= cl.max_temp_entities) + if (r_refdef.numtempentities >= r_refdef.maxtempentities) return NULL; - ent = &cl.temp_entities[cl.num_temp_entities++]; - memset (ent, 0, sizeof(*ent)); - r_refdef.entities[r_refdef.numentities++] = &ent->render; + render = &r_refdef.tempentities[r_refdef.numtempentities++]; + memset (render, 0, sizeof(*render)); + r_refdef.entities[r_refdef.numentities++] = render; - ent->render.alpha = 1; - VectorSet(ent->render.colormod, 1, 1, 1); - return ent; + render->alpha = 1; + VectorSet(render->colormod, 1, 1, 1); + return render; } void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate) @@ -810,7 +807,7 @@ void CL_RelinkLightFlashes(void) void CL_AddQWCTFFlagModel(entity_t *player, int skin) { float f; - entity_t *flag; + entity_render_t *flagrender; matrix4x4_t flagmatrix; // this code taken from QuakeWorld @@ -845,18 +842,18 @@ void CL_AddQWCTFFlagModel(entity_t *player, int skin) } // end of code taken from QuakeWorld - flag = CL_NewTempEntity(); - if (!flag) + flagrender = CL_NewTempEntity(); + if (!flagrender) return; - flag->render.model = cl.model_precache[cl.qw_modelindex_flag]; - flag->render.skinnum = skin; - flag->render.alpha = 1; - VectorSet(flag->render.colormod, 1, 1, 1); + flagrender->model = cl.model_precache[cl.qw_modelindex_flag]; + flagrender->skinnum = skin; + flagrender->alpha = 1; + VectorSet(flagrender->colormod, 1, 1, 1); // attach the flag to the player matrix Matrix4x4_CreateFromQuakeEntity(&flagmatrix, -f, -22, 0, 0, 0, -45, 1); - Matrix4x4_Concat(&flag->render.matrix, &player->render.matrix, &flagmatrix); - CL_UpdateRenderEntity(&flag->render); + Matrix4x4_Concat(&flagrender->matrix, &player->render.matrix, &flagmatrix); + CL_UpdateRenderEntity(flagrender); } matrix4x4_t viewmodelmatrix; @@ -1526,7 +1523,7 @@ static void CL_RelinkEffects(void) { int i, intframe; cl_effect_t *e; - entity_t *ent; + entity_render_t *entrender; float frame; for (i = 0, e = cl.effects;i < cl.num_effects;i++, e++) @@ -1552,27 +1549,27 @@ static void CL_RelinkEffects(void) // if we're drawing effects, get a new temp entity // (NewTempEntity adds it to the render entities list for us) - if (r_draweffects.integer && (ent = CL_NewTempEntity())) + if (r_draweffects.integer && (entrender = CL_NewTempEntity())) { // interpolation stuff - ent->render.frame1 = intframe; - ent->render.frame2 = intframe + 1; - if (ent->render.frame2 >= e->endframe) - ent->render.frame2 = -1; // disappear - ent->render.framelerp = frame - intframe; - ent->render.frame1time = e->frame1time; - ent->render.frame2time = e->frame2time; + entrender->frame1 = intframe; + entrender->frame2 = intframe + 1; + if (entrender->frame2 >= e->endframe) + entrender->frame2 = -1; // disappear + entrender->framelerp = frame - intframe; + entrender->frame1time = e->frame1time; + entrender->frame2time = e->frame2time; // normal stuff if(e->modelindex < MAX_MODELS) - ent->render.model = cl.model_precache[e->modelindex]; + entrender->model = cl.model_precache[e->modelindex]; else - ent->render.model = cl.csqc_model_precache[-(e->modelindex+1)]; - ent->render.alpha = 1; - VectorSet(ent->render.colormod, 1, 1, 1); + entrender->model = cl.csqc_model_precache[-(e->modelindex+1)]; + entrender->alpha = 1; + VectorSet(entrender->colormod, 1, 1, 1); - Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, e->origin[0], e->origin[1], e->origin[2], 0, 0, 0, 1); - CL_UpdateRenderEntity(&ent->render); + Matrix4x4_CreateFromQuakeEntity(&entrender->matrix, e->origin[0], e->origin[1], e->origin[2], 0, 0, 0, 1); + CL_UpdateRenderEntity(entrender); } } } @@ -1617,7 +1614,7 @@ void CL_RelinkBeams(void) beam_t *b; vec3_t dist, org, start, end; float d; - entity_t *ent; + entity_render_t *entrender; double yaw, pitch; float forward; matrix4x4_t tempmatrix; @@ -1676,17 +1673,17 @@ void CL_RelinkBeams(void) d = VectorNormalizeLength(dist); while (d > 0) { - ent = CL_NewTempEntity (); - if (!ent) + entrender = CL_NewTempEntity (); + if (!entrender) return; //VectorCopy (org, ent->render.origin); - ent->render.model = b->model; + entrender->model = b->model; //ent->render.effects = EF_FULLBRIGHT; //ent->render.angles[0] = pitch; //ent->render.angles[1] = yaw; //ent->render.angles[2] = rand()%360; - Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, org[0], org[1], org[2], -pitch, yaw, lhrandom(0, 360), 1); - CL_UpdateRenderEntity(&ent->render); + Matrix4x4_CreateFromQuakeEntity(&entrender->matrix, org[0], org[1], org[2], -pitch, yaw, lhrandom(0, 360), 1); + CL_UpdateRenderEntity(entrender); VectorMA(org, 30, dist, org); d -= 30; } @@ -1700,7 +1697,7 @@ static void CL_RelinkQWNails(void) { int i; vec_t *v; - entity_t *ent; + entity_render_t *entrender; for (i = 0;i < cl.qw_num_nails;i++) { @@ -1708,16 +1705,16 @@ static void CL_RelinkQWNails(void) // if we're drawing effects, get a new temp entity // (NewTempEntity adds it to the render entities list for us) - if (!(ent = CL_NewTempEntity())) + if (!(entrender = CL_NewTempEntity())) continue; // normal stuff - ent->render.model = cl.model_precache[cl.qw_modelindex_spike]; - ent->render.alpha = 1; - VectorSet(ent->render.colormod, 1, 1, 1); + entrender->model = cl.model_precache[cl.qw_modelindex_spike]; + entrender->alpha = 1; + VectorSet(entrender->colormod, 1, 1, 1); - Matrix4x4_CreateFromQuakeEntity(&ent->render.matrix, v[0], v[1], v[2], v[3], v[4], v[5], 1); - CL_UpdateRenderEntity(&ent->render); + Matrix4x4_CreateFromQuakeEntity(&entrender->matrix, v[0], v[1], v[2], v[3], v[4], v[5], 1); + CL_UpdateRenderEntity(entrender); } } @@ -2246,6 +2243,9 @@ void CL_Init (void) r_refdef.maxentities = MAX_EDICTS + 256 + 512; r_refdef.entities = (entity_render_t **)Mem_Alloc(cls.permanentmempool, sizeof(entity_render_t *) * r_refdef.maxentities); + r_refdef.maxtempentities = 512; + r_refdef.tempentities = (entity_render_t *)Mem_Alloc(cls.permanentmempool, sizeof(entity_render_t) * r_refdef.maxtempentities); + CL_InitInput (); // diff --git a/client.h b/client.h index bc1952fc..37793899 100644 --- a/client.h +++ b/client.h @@ -921,7 +921,6 @@ typedef struct client_state_s int max_entities; int max_static_entities; - int max_temp_entities; int max_effects; int max_beams; int max_dlights; @@ -934,7 +933,6 @@ typedef struct client_state_s entity_t *entities; unsigned char *entities_active; entity_t *static_entities; - entity_t *temp_entities; cl_effect_t *effects; beam_t *beams; dlight_t *dlights; @@ -946,7 +944,6 @@ typedef struct client_state_s int num_entities; int num_static_entities; - int num_temp_entities; int num_brushmodel_entities; int num_effects; int num_beams; @@ -1168,7 +1165,7 @@ void CL_Beam_CalculatePositions (const beam_t *b, vec3_t start, vec3_t end); void CL_ClientMovement_Replay(void); void CL_ClearTempEntities (void); -entity_t *CL_NewTempEntity (void); +entity_render_t *CL_NewTempEntity (void); void CL_Effect(vec3_t org, int modelindex, int startframe, int framecount, float framerate); @@ -1464,6 +1461,11 @@ typedef struct r_refdef_s int numentities; int maxentities; + // field of temporary entities that is reset each (client) frame + entity_render_t *tempentities; + int numtempentities; + int maxtempentities; + // renderable dynamic lights rtlight_t lights[MAX_DLIGHTS]; int numlights; diff --git a/csprogs.c b/csprogs.c index 995c0ed1..8627ea8f 100644 --- a/csprogs.c +++ b/csprogs.c @@ -129,7 +129,7 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed) int c; float scale; prvm_eval_t *val; - entity_t *e; + entity_render_t *entrender; model_t *model; matrix4x4_t tagmatrix, matrix2; @@ -137,20 +137,20 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed) if (!model) return false; - e = CL_NewTempEntity(); - if (!e) + entrender = CL_NewTempEntity(); + if (!entrender) return false; - e->render.model = model; - e->render.skinnum = (int)ed->fields.client->skin; - e->render.effects |= e->render.model->effects; + entrender->model = model; + entrender->skinnum = (int)ed->fields.client->skin; + entrender->effects |= entrender->model->effects; scale = 1; renderflags = 0; if((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.renderflags)) && val->_float) renderflags = (int)val->_float; - if((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.alpha)) && val->_float) e->render.alpha = val->_float; - if((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.scale)) && val->_float) e->render.scale = scale = val->_float; - if((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.colormod)) && VectorLength2(val->vector)) VectorCopy(val->vector, e->render.colormod); - if((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.effects)) && val->_float) e->render.effects |= (int)val->_float; + if((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.alpha)) && val->_float) entrender->alpha = val->_float; + if((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.scale)) && val->_float) entrender->scale = scale = val->_float; + if((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.colormod)) && VectorLength2(val->vector)) VectorCopy(val->vector, entrender->colormod); + if((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.effects)) && val->_float) entrender->effects |= (int)val->_float; if((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.tag_entity)) && val->edict) { int tagentity; @@ -175,7 +175,7 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed) vec3_t angles; VectorCopy(ed->fields.client->angles, angles); // if model is alias, reverse pitch direction - if (e->render.model->type == mod_alias) + if (entrender->model->type == mod_alias) angles[0] = -angles[0]; // set up the render matrix @@ -187,45 +187,45 @@ qboolean CSQC_AddRenderEdict(prvm_edict_t *ed) // self.frame1time is the animation base time for the interpolation target // self.frame2 is the interpolation start (previous frame) // self.frame2time is the animation base time for the interpolation start - e->render.frame1 = e->render.frame2 = ed->fields.client->frame; - if ((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.frame2))) e->render.frame2 = val->_float; - if ((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.frame1time))) e->render.frame2time = val->_float; - if ((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.frame2time))) e->render.frame1time = val->_float; - if ((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.lerpfrac))) e->render.framelerp = val->_float; + entrender->frame1 = entrender->frame2 = ed->fields.client->frame; + if ((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.frame2))) entrender->frame2 = val->_float; + if ((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.frame1time))) entrender->frame2time = val->_float; + if ((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.frame2time))) entrender->frame1time = val->_float; + if ((val = PRVM_EDICTFIELDVALUE(ed, prog->fieldoffsets.lerpfrac))) entrender->framelerp = val->_float; // concat the matrices to make the entity relative to its tag - Matrix4x4_Concat(&e->render.matrix, &tagmatrix, &matrix2); + Matrix4x4_Concat(&entrender->matrix, &tagmatrix, &matrix2); if(renderflags) { - if(renderflags & RF_VIEWMODEL) e->render.flags |= RENDER_VIEWMODEL; - if(renderflags & RF_EXTERNALMODEL)e->render.flags |= RENDER_EXTERIORMODEL; - if(renderflags & RF_DEPTHHACK) e->render.effects |= EF_NODEPTHTEST; - if(renderflags & RF_ADDITIVE) e->render.effects |= EF_ADDITIVE; + if(renderflags & RF_VIEWMODEL) entrender->flags |= RENDER_VIEWMODEL; + if(renderflags & RF_EXTERNALMODEL)entrender->flags |= RENDER_EXTERIORMODEL; + if(renderflags & RF_DEPTHHACK) entrender->effects |= EF_NODEPTHTEST; + if(renderflags & RF_ADDITIVE) entrender->effects |= EF_ADDITIVE; } c = (int)ed->fields.client->colormap; if (c <= 0) - CL_SetEntityColormapColors(&e->render, -1); + CL_SetEntityColormapColors(entrender, -1); else if (c <= cl.maxclients && cl.scores != NULL) - CL_SetEntityColormapColors(&e->render, cl.scores[c-1].colors); + CL_SetEntityColormapColors(entrender, cl.scores[c-1].colors); else - CL_SetEntityColormapColors(&e->render, c); + CL_SetEntityColormapColors(entrender, c); // either fullbright or lit - if (!(e->render.effects & EF_FULLBRIGHT) && !r_fullbright.integer) - e->render.flags |= RENDER_LIGHT; + if (!(entrender->effects & EF_FULLBRIGHT) && !r_fullbright.integer) + entrender->flags |= RENDER_LIGHT; // hide player shadow during intermission or nehahra movie - if (!(e->render.effects & (EF_NOSHADOW | EF_ADDITIVE | EF_NODEPTHTEST)) - && (e->render.alpha >= 1) - && !(e->render.flags & RENDER_VIEWMODEL) - && (!(e->render.flags & RENDER_EXTERIORMODEL) || (!cl.intermission && cls.protocol != PROTOCOL_NEHAHRAMOVIE && !cl_noplayershadow.integer))) - e->render.flags |= RENDER_SHADOW; - if (e->render.flags & RENDER_VIEWMODEL) - e->render.flags |= RENDER_NOSELFSHADOW; + if (!(entrender->effects & (EF_NOSHADOW | EF_ADDITIVE | EF_NODEPTHTEST)) + && (entrender->alpha >= 1) + && !(entrender->flags & RENDER_VIEWMODEL) + && (!(entrender->flags & RENDER_EXTERIORMODEL) || (!cl.intermission && cls.protocol != PROTOCOL_NEHAHRAMOVIE && !cl_noplayershadow.integer))) + entrender->flags |= RENDER_SHADOW; + if (entrender->flags & RENDER_VIEWMODEL) + entrender->flags |= RENDER_NOSELFSHADOW; // make the other useful stuff - CL_UpdateRenderEntity(&e->render); + CL_UpdateRenderEntity(entrender); return true; } diff --git a/menu.c b/menu.c index 1cb85402..9197bee6 100644 --- a/menu.c +++ b/menu.c @@ -5074,11 +5074,14 @@ void MP_Draw (void) clientrefdef = r_refdef; r_refdef = menu_refdef; - PRVM_Begin; - PRVM_SetProg(PRVM_MENUPROG); + // reset the temp entities each frame + r_refdef.numtempentities = 0; R_UpdateVariables(); + PRVM_Begin; + PRVM_SetProg(PRVM_MENUPROG); + // FIXME: this really shouldnt error out lest we have a very broken refdef state...? // or does it kill the server too? PRVM_ExecuteProgram(prog->funcoffsets.m_draw,"m_draw() required"); @@ -5143,9 +5146,6 @@ void MP_Init (void) // call the prog init PRVM_ExecuteProgram(prog->funcoffsets.m_init,"m_init() required"); - // FIXME: needed so cl.max_entities is set - CL_ClearState (); - PRVM_End; } diff --git a/mvm_cmds.c b/mvm_cmds.c index 36c759a2..1509c1b9 100644 --- a/mvm_cmds.c +++ b/mvm_cmds.c @@ -1432,6 +1432,9 @@ void VM_M_Cmd_Init(void) VM_Polygons_Reset(); memset (&menu_refdef, 0, sizeof (r_refdef_t)); + + menu_refdef.maxtempentities = 128; + menu_refdef.tempentities = (entity_render_t*) Mem_Alloc(prog->progs_mempool, sizeof(entity_render_t) * menu_refdef.maxtempentities); menu_refdef.frustumscale_x = 1; menu_refdef.frustumscale_y = 1;