Skip to content

Commit

Permalink
Optimize: Store a ptr to material in animframe_t rather than a materi…
Browse files Browse the repository at this point in the history
…al type plus index so that there is no need to look it up.

Moved R_PrecacheMaterial() into r_materials.c
Various other minor tweaks and cleanup.
  • Loading branch information
danij committed Apr 1, 2008
1 parent 7a85ef8 commit 6e41c6c
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 165 deletions.
3 changes: 1 addition & 2 deletions doomsday/engine/portable/include/r_data.h
Expand Up @@ -288,8 +288,7 @@ typedef struct rawtex_s {
} rawtex_t;

typedef struct animframe_s {
int number;
materialtype_t type;
material_t *mat;
ushort tics;
ushort random;
} animframe_t;
Expand Down
3 changes: 3 additions & 0 deletions doomsday/engine/portable/include/r_materials.h
Expand Up @@ -67,8 +67,11 @@ boolean R_IsCustomMaterial(int ofTypeID, materialtype_t type);
int R_GetMaterialFlags(material_t *material);
boolean R_GetMaterialColor(const material_t *material, float *rgb);

void R_PrecacheMaterial(material_t *mat);

// Returns the real DGL texture, if such exists
unsigned int R_GetMaterialName(int ofTypeID, materialtype_t type);
ded_reflection_t* R_GetMaterialReflection(material_t* mat);
const ded_decor_t* R_GetMaterialDecoration(const material_t* mat);
const ded_ptcgen_t* P_GetMaterialPtcGen(const material_t* mat);

Expand Down
37 changes: 18 additions & 19 deletions doomsday/engine/portable/src/gl_texmanager.c
Expand Up @@ -544,20 +544,17 @@ void GL_DeleteFlareMap(ded_flaremap_t *map)
* Loads both the shiny texture and the mask. Returns true if there is
* a reflection map to can be used.
*/
boolean GL_LoadReflectionMap(ded_reflection_t *loading_ref)
boolean GL_LoadReflectionMap(ded_reflection_t* loadingRef)
{
ded_reflection_t *ref;
ded_reflection_t* ref;

if(loading_ref == NULL)
{
if(!loadingRef)
return false;
}

// First try the shiny texture map.
ref = loading_ref->useShiny;
ref = loadingRef->useShiny;
if(!ref)
{
// Not shiny at all.
{ // Not shiny at all.
return false;
}

Expand All @@ -574,9 +571,9 @@ boolean GL_LoadReflectionMap(ded_reflection_t *loading_ref)
}

// Also load the mask, if one has been specified.
if(loading_ref->useMask)
if(loadingRef->useMask)
{
ref = loading_ref->useMask;
ref = loadingRef->useMask;

if(ref->maskTex == 0)
{
Expand Down Expand Up @@ -1280,11 +1277,6 @@ DGLuint GL_PrepareDetailTexture(int index, boolean is_wall_texture,
*/
static unsigned int prepareFlat2(int idx, texinfo_t **info, byte *result)
{
byte *flatptr;
int width, height, pixSize = 3;
boolean RGBData = false, freeptr = false;
ded_detailtexture_t *def;
image_t image;
flat_t *flat;

if(idx < 0 || idx >= numFlats) // No texture?
Expand All @@ -1298,6 +1290,12 @@ static unsigned int prepareFlat2(int idx, texinfo_t **info, byte *result)
}
else
{
byte *flatptr;
int width, height, pixSize = 3;
boolean RGBData = false, freeptr = false;
ded_detailtexture_t *def;
image_t image;

// Try to load a high resolution version of this flat.
if((loadExtAlways || highResWithPWAD ||
!R_IsCustomMaterial(idx, MAT_FLAT)) &&
Expand Down Expand Up @@ -1756,11 +1754,7 @@ boolean GL_BufferTexture(texture_t *tex, byte *buffer, int width, int height,
*/
static DGLuint prepareTexture2(int idx, texinfo_t **info, byte *result)
{
ded_detailtexture_t *def;
texture_t *tex;
boolean alphaChannel = false, RGBData = false;
int i;
image_t image;

if(idx < 0 || idx >= numTextures) // No texture?
return 0;
Expand All @@ -1773,6 +1767,11 @@ static DGLuint prepareTexture2(int idx, texinfo_t **info, byte *result)
}
else
{
int i;
image_t image;
ded_detailtexture_t *def;
boolean alphaChannel = false, RGBData = false;

// Try to load a high resolution version of this texture.
if((loadExtAlways || highResWithPWAD ||
!R_IsCustomMaterial(idx, MAT_TEXTURE)) &&
Expand Down
60 changes: 9 additions & 51 deletions doomsday/engine/portable/src/r_data.c
Expand Up @@ -551,8 +551,7 @@ void R_AddToAnimGroup(int groupNum, const char *name, materialtype_t type,

frame = group->frames + group->count - 1;

frame->number = number;
frame->type = type;
frame->mat = mat;
frame->tics = tics;
frame->random = randomTics;
}
Expand All @@ -561,6 +560,7 @@ boolean R_IsInAnimGroup(int groupNum, materialtype_t type, int number)
{
int i;
animgroup_t *group = R_GetAnimGroup(groupNum);
material_t *mat = R_GetMaterial(number, type);

if(!group)
return false;
Expand All @@ -570,7 +570,7 @@ boolean R_IsInAnimGroup(int groupNum, materialtype_t type, int number)
{
animframe_t *frame = &group->frames[i];

if(frame->number == number && frame->type == type)
if(frame->mat == mat)
return true;
}

Expand Down Expand Up @@ -1196,40 +1196,6 @@ void R_PrecachePatch(lumpnum_t num)
GL_PreparePatch(num, NULL);
}

/**
* Prepares all resources associated with the specified material including
* all in the same animation group.
*/
void R_PrecacheMaterial(material_t *mat)
{
if(mat->inGroup)
{ // The material belongs in one or more animgroups.
int i;

for(i = 0; i < numgroups; ++i)
{
if(R_IsInAnimGroup(groups[i].id, mat->type, mat->ofTypeID))
{
int k;

// Precache this group.
for(k = 0; k < groups[i].count; ++k)
{
animframe_t *frame = &groups[i].frames[k];

GL_PrepareMaterial(R_GetMaterial(frame->number,
frame->type), NULL);
}
}
}

return;
}

// Just this one material.
GL_PrepareMaterial(mat, NULL);
}

static boolean isInList(void **list, size_t len, void *elm)
{
size_t n;
Expand Down Expand Up @@ -1398,19 +1364,13 @@ void R_AnimateAnimGroups(void)
// Update texture/flat translations.
for(k = 0; k < group->count; ++k)
{
int rIDX, cIDX, nIDX;
material_t *real, *current, *next;

rIDX = k;
cIDX = (group->index + k) % group->count;
nIDX = (group->index + k + 1) % group->count;

real = R_GetMaterial(group->frames[rIDX].number,
group->frames[rIDX].type);
current = R_GetMaterial(group->frames[cIDX].number,
group->frames[cIDX].type);
next = R_GetMaterial(group->frames[nIDX].number,
group->frames[nIDX].type);
real = group->frames[k].mat;
current =
group->frames[(group->index + k) % group->count].mat;
next =
group->frames[(group->index + k + 1) % group->count].mat;

R_SetMaterialTranslation(real, current, next, 0);

Expand All @@ -1424,9 +1384,7 @@ void R_AnimateAnimGroups(void)
// Update the interpolation point of animated group members.
for(k = 0; k < group->count; ++k)
{
material_t *mat =
R_GetMaterial(group->frames[k].number,
group->frames[k].type);
material_t *mat = group->frames[k].mat;

if(group->flags & AGF_SMOOTH)
{
Expand Down
26 changes: 13 additions & 13 deletions doomsday/engine/portable/src/r_lumobjs.c
Expand Up @@ -345,25 +345,25 @@ lumobj_t *LO_GetLuminous(uint idx)
*/
void LO_AddLuminous(mobj_t *mo)
{
uint i;
float mul, xOff, center;
int flags = 0;
int radius, flareSize;
float rgb[3];
lumobj_t *l;
lightconfig_t cf;
ded_light_t *def = 0;
spritedef_t *sprDef;
spriteframe_t *sprFrame;
spritetex_t *sprTex;
material_t *mat;

mo->light = 0;

if(((mo->state && (mo->state->flags & STF_FULLBRIGHT)) &&
!(mo->ddFlags & DDMF_DONTDRAW)) ||
(mo->ddFlags & DDMF_ALWAYSLIT))
{
uint i;
float mul, xOff, center;
int flags = 0;
int radius, flareSize;
float rgb[3];
lumobj_t *l;
lightconfig_t cf;
ded_light_t *def = 0;
spritedef_t *sprDef;
spriteframe_t *sprFrame;
spritetex_t *sprTex;
material_t *mat;

// Are the automatically calculated light values for fullbright
// sprite frames in use?
if(mo->state &&
Expand Down
48 changes: 47 additions & 1 deletion doomsday/engine/portable/src/r_materials.c
Expand Up @@ -366,10 +366,56 @@ int R_GetMaterialFlags(material_t *mat)
};
}

/**
* Prepares all resources associated with the specified material including
* all in the same animation group.
*/
void R_PrecacheMaterial(material_t *mat)
{
if(mat->inGroup)
{ // The material belongs in one or more animgroups.
int i;

for(i = 0; i < numgroups; ++i)
{
if(R_IsInAnimGroup(groups[i].id, mat->type, mat->ofTypeID))
{
int k;

// Precache this group.
for(k = 0; k < groups[i].count; ++k)
{
animframe_t *frame = &groups[i].frames[k];

GL_PrepareMaterial(frame->mat, NULL);
}
}
}

return;
}

// Just this one material.
GL_PrepareMaterial(mat, NULL);
}

/**
* Retrieve the reflection definition associated with the material.
*
* @return The associated reflection definition, else @c NULL.
*/
ded_reflection_t* R_GetMaterialReflection(material_t* mat)
{
if(!mat)
return NULL;

return mat->reflection;
}

/**
* Retrieve the decoration definition associated with the material.
*
* @return The associated decoration definition, else @c NULL
* @return The associated decoration definition, else @c NULL.
*/
const ded_decor_t* R_GetMaterialDecoration(const material_t* mat)
{
Expand Down
5 changes: 0 additions & 5 deletions doomsday/engine/portable/src/rend_fakeradio.c
Expand Up @@ -1215,11 +1215,6 @@ static void radioAddShadowEdge(const linedef_t *line, byte side,
q = R_AllocRendPoly(RP_FLAT, false, 4);
if(!renderWireframe)
q->flags = RPF_SHADOW;
memset(&q->tex, 0, sizeof(q->tex));
memset(&q->interTex, 0, sizeof(q->interTex));
q->interPos = 0;
q->lightListIdx = 0;
memset(q->vertices, 0, q->numVertices * sizeof(rendpoly_vertex_t));

q->normal[0] = normal[VX];
q->normal[1] = normal[VY];
Expand Down

0 comments on commit 6e41c6c

Please sign in to comment.