From 6e41c6cf99c55b4bec59a883b5c03b442a5d831f Mon Sep 17 00:00:00 2001 From: danij Date: Tue, 1 Apr 2008 15:11:02 +0000 Subject: [PATCH] Optimize: Store a ptr to material in animframe_t rather than a material 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. --- doomsday/engine/portable/include/r_data.h | 3 +- .../engine/portable/include/r_materials.h | 3 + doomsday/engine/portable/src/gl_texmanager.c | 37 +++--- doomsday/engine/portable/src/r_data.c | 60 ++-------- doomsday/engine/portable/src/r_lumobjs.c | 26 ++--- doomsday/engine/portable/src/r_materials.c | 48 +++++++- doomsday/engine/portable/src/rend_fakeradio.c | 5 - doomsday/engine/portable/src/rend_main.c | 106 ++++++------------ 8 files changed, 123 insertions(+), 165 deletions(-) diff --git a/doomsday/engine/portable/include/r_data.h b/doomsday/engine/portable/include/r_data.h index 6016be7872..2e2cc66578 100644 --- a/doomsday/engine/portable/include/r_data.h +++ b/doomsday/engine/portable/include/r_data.h @@ -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; diff --git a/doomsday/engine/portable/include/r_materials.h b/doomsday/engine/portable/include/r_materials.h index 34c5c923cb..ce35d26f58 100644 --- a/doomsday/engine/portable/include/r_materials.h +++ b/doomsday/engine/portable/include/r_materials.h @@ -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); diff --git a/doomsday/engine/portable/src/gl_texmanager.c b/doomsday/engine/portable/src/gl_texmanager.c index 6339e692c4..168d492b5d 100644 --- a/doomsday/engine/portable/src/gl_texmanager.c +++ b/doomsday/engine/portable/src/gl_texmanager.c @@ -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; } @@ -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) { @@ -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? @@ -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)) && @@ -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; @@ -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)) && diff --git a/doomsday/engine/portable/src/r_data.c b/doomsday/engine/portable/src/r_data.c index 4c18df9bf6..a61cacbb2f 100644 --- a/doomsday/engine/portable/src/r_data.c +++ b/doomsday/engine/portable/src/r_data.c @@ -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; } @@ -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; @@ -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; } @@ -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; @@ -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); @@ -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) { diff --git a/doomsday/engine/portable/src/r_lumobjs.c b/doomsday/engine/portable/src/r_lumobjs.c index 32adae793b..4255ab1192 100644 --- a/doomsday/engine/portable/src/r_lumobjs.c +++ b/doomsday/engine/portable/src/r_lumobjs.c @@ -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 && diff --git a/doomsday/engine/portable/src/r_materials.c b/doomsday/engine/portable/src/r_materials.c index c0d96d2c23..4cb342cc79 100644 --- a/doomsday/engine/portable/src/r_materials.c +++ b/doomsday/engine/portable/src/r_materials.c @@ -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) { diff --git a/doomsday/engine/portable/src/rend_fakeradio.c b/doomsday/engine/portable/src/rend_fakeradio.c index 044de94ff1..b4d326567a 100644 --- a/doomsday/engine/portable/src/rend_fakeradio.c +++ b/doomsday/engine/portable/src/rend_fakeradio.c @@ -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]; diff --git a/doomsday/engine/portable/src/rend_main.c b/doomsday/engine/portable/src/rend_main.c index 0754c37ae2..9831b4821b 100644 --- a/doomsday/engine/portable/src/rend_main.c +++ b/doomsday/engine/portable/src/rend_main.c @@ -270,7 +270,8 @@ static int C_DECL DivSortDescend(const void *e1, const void *e2) return 0; } -static void Rend_ShinySurfaceColor(float color[4], ded_reflection_t *ref) +static void Rend_ShinySurfaceColor(float color[4], + const ded_reflection_t* ref) { uint i; @@ -288,53 +289,6 @@ static void Rend_ShinySurfaceColor(float color[4], ded_reflection_t *ref) color[CA]);*/ } -static ded_reflection_t *getReflectionDef(material_t *mat, short *width, - short *height) -{ - ded_reflection_t *ref = NULL; - - if(!mat) - return NULL; - - // Figure out what kind of surface properties have been defined - // for the texture or flat in question. - switch(mat->current->type) - { - case MAT_FLAT: - { - flat_t *flatptr = flats[mat->current->ofTypeID]; - - ref = mat->current->reflection; - if(ref) - { - if(width) - *width = flatptr->info.width; - if(height) - *height = flatptr->info.height; - } - break; - } - case MAT_TEXTURE: - { - texture_t *texptr = textures[mat->current->ofTypeID]; - - ref = mat->current->reflection; - if(ref) - { - if(width) - *width = texptr->info.width; - if(height) - *height = texptr->info.height; - } - break; - } - default: - break; - } - - return ref; -} - /** * \pre As we modify param poly quite a bit it is the responsibility of * the caller to ensure this is OK (ie if not it should pass us a @@ -344,7 +298,7 @@ static ded_reflection_t *getReflectionDef(material_t *mat, short *width, * @param isFlat @c true = param texture is a flat. * @param poly The poly to add the shiny poly for. */ -static void Rend_AddShinyPoly(rendpoly_t *poly, ded_reflection_t *ref, +static void Rend_AddShinyPoly(rendpoly_t *poly, const ded_reflection_t* ref, short width, short height) { uint i; @@ -526,6 +480,7 @@ void Rend_VertexColors(rendpoly_t* poly, float lightLevel, void Rend_VertexColorsApplyTorchLight(rendpoly_t *poly) { int i; + ddplayer_t *ddpl = &viewPlayer->shared; // Check for special case exceptions. if(poly->flags & (RPF_SKY_MASK|RPF_LIGHT|RPF_SHADOW|RPF_GLOW)) @@ -533,6 +488,9 @@ void Rend_VertexColorsApplyTorchLight(rendpoly_t *poly) return; // Don't receive light from torches. } + if(!ddpl->fixedColorMap) + return; // No need, its disabled. + for(i = 0; i < poly->numVertices; ++i) { rendpoly_vertex_t *vtx = &poly->vertices[i]; @@ -792,8 +750,7 @@ static int prepareMaterialForPoly(rendpoly_t *poly, surface_t *surface, } else if(surface->material) { - poly->tex.id = curTex = - GL_PrepareMaterial(surface->material, &info); + poly->tex.id = curTex = GL_PrepareMaterial(surface->material, &info); flags = surface->flags; //// \kludge > @@ -1126,7 +1083,10 @@ static void doRenderPlane(rendpoly_t *poly, sector_t *polySector, skyhemispheres |= (plane->type == PLN_FLOOR? SKYHEMI_LOWER : SKYHEMI_UPPER); } else - poly->lightListIdx = DL_ProcessSubSectorPlane(subsector, plane->planeID); + { + poly->lightListIdx = + DL_ProcessSubSectorPlane(subsector, plane->planeID); + } // Smooth Texture Animation? if(flags & RPF2_BLEND) @@ -1141,17 +1101,15 @@ static void doRenderPlane(rendpoly_t *poly, sector_t *polySector, // Render Shiny polys for this seg? if((flags & RPF2_SHINY) && useShinySurfaces) { - ded_reflection_t *ref; - short width = 0; - short height = 0; + ded_reflection_t* ref = R_GetMaterialReflection(surface->material); - if((ref = getReflectionDef(surface->material, &width, &height)) != NULL) + // Make sure the texture has been loaded. + if(GL_LoadReflectionMap(ref)) { - // Make sure the texture has been loaded. - if(GL_LoadReflectionMap(ref)) - { - Rend_AddShinyPoly(poly, ref, width, height); - } + texinfo_t* texInfo; + + GL_GetMaterialInfo2(surface->material, false, &texInfo); + Rend_AddShinyPoly(poly, ref, texInfo->width, texInfo->height); } } } @@ -1456,22 +1414,22 @@ static boolean renderSegSection(seg_t *seg, segsection_t section, surface_t *sur // Render Shiny polys for this seg? if((tempflags & RPF2_SHINY) && useShinySurfaces) { - ded_reflection_t *ref; - short width = 0; - short height = 0; + ded_reflection_t* ref = + R_GetMaterialReflection(surface->material); - if((ref = getReflectionDef(surface->material, &width, &height)) != NULL) + // Make sure the texture has been loaded. + if(GL_LoadReflectionMap(ref)) { - // Make sure the texture has been loaded. - if(GL_LoadReflectionMap(ref)) - { - // We're going to modify the polygon quite a bit... - rendpoly_t *q = R_AllocRendPoly(RP_QUAD, true, 4); - R_MemcpyRendPoly(q, quad); - Rend_AddShinyPoly(q, ref, width, height); + // We're going to modify the polygon quite a bit... + rendpoly_t* q; + texinfo_t* texInfo; - R_FreeRendPoly(q); - } + GL_GetMaterialInfo2(surface->material, false, &texInfo); + + q = R_AllocRendPoly(RP_QUAD, true, 4); + R_MemcpyRendPoly(q, quad); + Rend_AddShinyPoly(q, ref, texInfo->width, texInfo->height); + R_FreeRendPoly(q); } } }