mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-21 18:01:15 +00:00
Avoid using malloc/free every model/frame.
This commit is contained in:
parent
c2e0674d50
commit
2080c337d7
3 changed files with 9 additions and 12 deletions
|
@ -78,7 +78,7 @@ void R_EnqueueEntity (struct entity_s *ent);
|
|||
entity_t *R_AllocEntity (void);
|
||||
void R_FreeAllEntities (void);
|
||||
|
||||
dlight_t **R_FindNearLights (const vec3_t pos, int count);
|
||||
void R_FindNearLights (const vec3_t pos, int count, dlight_t **lights);
|
||||
dlight_t *R_AllocDlight (int key);
|
||||
void R_DecayLights (double frametime);
|
||||
void R_ClearDlights (void);
|
||||
|
|
|
@ -195,14 +195,14 @@ glsl_R_DrawIQM (void)
|
|||
entity_t *ent = currententity;
|
||||
model_t *model = ent->model;
|
||||
iqm_t *iqm = (iqm_t *) model->aliashdr;
|
||||
dlight_t **lights;
|
||||
dlight_t *lights[MAX_IQM_LIGHTS];
|
||||
int i;
|
||||
vec_t norm_mat[9];
|
||||
mat4_t mvp_mat;
|
||||
float blend;
|
||||
iqmframe_t *frame;
|
||||
|
||||
lights = R_FindNearLights (ent->origin, MAX_IQM_LIGHTS);
|
||||
R_FindNearLights (ent->origin, MAX_IQM_LIGHTS, lights);
|
||||
|
||||
// we need only the rotation for normals.
|
||||
VectorCopy (ent->transform + 0, norm_mat + 0);
|
||||
|
@ -212,7 +212,7 @@ glsl_R_DrawIQM (void)
|
|||
|
||||
blend = R_IQMGetLerpedFrames (ent, iqm);
|
||||
|
||||
frame = malloc (iqm->num_joints * sizeof (iqmframe_t));
|
||||
frame = Hunk_TempAlloc (iqm->num_joints * sizeof (iqmframe_t));
|
||||
for (i = 0; i < iqm->num_joints; i++) {
|
||||
iqmframe_t *f1 = &iqm->frames[ent->pose1][i];
|
||||
iqmframe_t *f2 = &iqm->frames[ent->pose2][i];
|
||||
|
@ -249,8 +249,6 @@ glsl_R_DrawIQM (void)
|
|||
GL_UNSIGNED_SHORT,
|
||||
iqm->elements + 3 * iqm->meshes[i].first_triangle);
|
||||
}
|
||||
free (frame);
|
||||
free (lights);
|
||||
}
|
||||
|
||||
// All iqm models are drawn in a batch, so avoid thrashing the gl state
|
||||
|
|
|
@ -49,11 +49,10 @@ vec3_t ambientcolor;
|
|||
|
||||
unsigned int r_maxdlights;
|
||||
|
||||
dlight_t **
|
||||
R_FindNearLights (const vec3_t pos, int count)
|
||||
void
|
||||
R_FindNearLights (const vec3_t pos, int count, dlight_t **lights)
|
||||
{
|
||||
dlight_t **lights = calloc (count, sizeof (dlight_t *));
|
||||
float *scores = calloc (count, sizeof (float));
|
||||
float *scores = alloca (count * sizeof (float));
|
||||
float score;
|
||||
dlight_t *dl;
|
||||
unsigned i;
|
||||
|
@ -100,8 +99,8 @@ R_FindNearLights (const vec3_t pos, int count)
|
|||
}
|
||||
}
|
||||
}
|
||||
free (scores);
|
||||
return lights;
|
||||
for (j = num; j < count; j++)
|
||||
lights[j] = 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in a new issue